2

我从文本框中检索关键字并希望刷新绑定到 LinqDataSource 的 GridView。

我假设我可以在 OnTextChanged 函数中执行此操作,如下所示

    protected void OnTextChanged(object sender, EventArgs e)
    {
     // do LINQ query based on content in textbox
     catalogDataContext dc = new catalogDataContext();
     var query = from product in dc.catalog
                 where product.Name.Contains(TextBox.Text)
                 select product;     

     // what do I have to do here to refresh the GridView? Thanks.


    GridView.DataBind();
    }
4

1 回答 1

0

首先使用 linq 源的数据绑定方法刷新数据上下文。然后使用 gridView 的 databind 方法将网格视图刷新到新的上下文。提示:如果您愿意,请将您的 gridView 放在 AJAX 更新面板中 - 这样生成的页面会好得多。

于 2014-02-21T14:20:22.220 回答