【问题标题】:LINQ: How to refresh a GridView bound to LinqDataSource?LINQ:如何刷新绑定到 LinqDataSource 的 GridView?
【发布时间】:2011-12-31 20:22:21
【问题描述】:

我从文本框中检索关键字并希望刷新绑定到 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();
    }

【问题讨论】:

  • 你试过了吗?成功了,对吧?

标签: asp.net linq gridview linqdatasource


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-09
    • 2013-09-13
    • 2012-04-20
    • 2011-09-29
    • 1970-01-01
    • 2023-03-20
    • 2013-07-22
    相关资源
    最近更新 更多