LINQ:如何刷新绑定到 LinqDataSource 的 GridView?
我从文本框中检索关键字并想要刷新绑定到 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();
}
I retrieve keywords from a textbox and want to refresh a GridView that is bound to a LinqDataSource.
I assume I can do this in the OnTextChanged function as follows
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先使用 linq 源的 databind 方法刷新数据上下文。然后使用 gridView 的 databind 方法将网格视图刷新到新的上下文。
提示:如果您愿意,请将 gridView 放入 AJAX 更新面板中 - 这样生成的页面会好得多。
Use your linq source's databind method to refresh data context first. Then use gridView's databind method to refresh grid view to new context.
TIP: if you want, put your gridView in AJAX update panel - the resulting page is much better that way.