防止在每次回发时选择 LinqDataSource
页面中有一个GridView和一个LinqDataSource,以及一些按钮,它们的操作与GridView及其LinqDataSource无关。为什么在这些按钮的每次回发时,LinqDataSource 的 Selecting 方法都会调用?这正常吗?! 不需要来自 LinqDataSource 的这些不需要的数据库调用。
还有更好的办法吗?
There are a GridView and a LinqDataSource in a page and few buttons which their actions are not related to the GridView and its LinqDataSource. Why on each post-back of those buttons the Selecting method of the LinqDataSource will call? Is this normal?!
These unwanted db calls from the LinqDataSource are not required.
Is there any better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 GridView 从数据源中分离出来。我假设您已经像这样附加了数据源,在这种情况下,不要这样做。
您最好在需要时将数据源附加到代码后面。
You need to detach the GridView from the data source. I assume you have attached the data source like this, in which case, don't do it this way.
Your better off attaching the data source in your code behind when it's needed.
因为网格需要在每次页面加载时填充,您可以将数据源缓存到某个变量并将其存储在服务器端(而不是在视图状态中)
it because grid need to populated on every page load, you may cache datasorce to some variable and store it on the server side (not in viewstate)