Asp.net实体框架Gridview筛选器不起作用

时间:2018-08-03 06:47:43

标签: asp.net entity-framework

protected void FilterButton_Click(object sender, EventArgs e)

    {
        if (string.IsNullOrEmpty(this.FilterTextBox.Text))
        {
            this.GridView1.DataSource = db.Yetenekler.Local.ToBindingList();
        }
        else
        {
            var filteredData = db.Yetenekler.Local
                                 .Where(x => x.adi.Contains(this.FilterTextBox.Text));
            this.GridView1.DataSource = filteredData;
        }
    }

返回

1 个答案:

答案 0 :(得分:0)

您需要将数据绑定到网格.DataBind();上以刷新它。

protected void FilterButton_Click(object sender, EventArgs e)

{
    if (string.IsNullOrEmpty(this.FilterTextBox.Text))
    {
        this.GridView1.DataSource = db.Yetenekler.Local.ToBindingList();
        this.GridView1.DataBind();
    }
    else
    {
        var filteredData = db.Yetenekler.Local
                             .Where(x => x.adi.Contains(this.FilterTextBox.Text));
        this.GridView1.DataSource = filteredData.ToList();
        this.GridView1.DataBind();
    }
}