How to filter gridview from textbox?

前端 未结 3 1259
北荒
北荒 2020-12-18 17:02

I need to filter a gridview that retreives filtered data from a table. Therefore I bound the gridview to a dataset. Now i can\'t seem to find a solution to filter it further

3条回答
  •  清酒与你
    2020-12-18 17:14

    Try this:

    protected void Button1_Click(object sender, EventArgs e)
    {
    
        DataSet ds = new DataSet();
        SqlConnection myCon = new SqlConnection(connectionstring);
        SqlDataAdapter adapter = new SqlDataAdapter(cmd, myCon);
        adapter.Fill(ds);
        DataView view = new DataView();
        view.Table = ds.Tables[0];
        view.RowFilter = "ColumnName = " + TextBox1.Text.Trim();
        GridView1.DataSource = view;
        GridView1.DataBind();
    }
    
    • you have to refactor your code.

提交回复
热议问题