谢谢!!
可以把上次的查询结果生成一个视图,然后再在视图里面查询。
用ViewState来记录要过滤字段就行了。
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
DataGridBind();
}
}
private void DataGridBind()
{
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string strSql = "SELECT * FROM table1";
SqlDataAdapter myAdp = new SqlDataAdapter(strSql,conn);
DataSet ds = new DataSet();
myAdp.Fill(ds,"fill");
DataView dv = ds.Tables[0].DefaultView;
if (ViewState["rowfilter"]!=null)
{
dv.RowFilter = ViewState["rowfilter"].ToString();
}
this.DataGrid1.DataSource = dv;
this.DataGrid1.DataBind();
conn.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
if (ViewState["rowfilter"]==null)
{
ViewState["rowfilter"] = this.TextBox1.Text;
}
else
{
ViewState["rowfilter"] = ViewState["rowfilter"].ToString() + " and " + this.TextBox1.Text;
}
DataGridBind();
}