ViewState中Datagrid的DataSource?

编程入门 行业动态 更新时间:2024-10-14 10:40:47
本文介绍了ViewState中Datagrid的DataSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在ViewState中存储GridView的DataSource是否合适,以便在PageLoad on按钮上单击回发时我不需要再次从数据库加载数据源。 是它是在ViewState中存储数据源的正确方法吗?

Is it good to store DataSource of GridView in ViewState, so that while on PageLoad on button click postback I need not to load datasource from database again. Is it a correct approach to store datasource in ViewState?

推荐答案

1.不能存储在 ViewState 中,因为在这种情况下,网格数据将在 ViewState 中存储两次( GridView 对象本身及其所有行都存储在回发之间的视图状态)。 还有关于你将在网格中添加,编辑和/或删除的情况==>这将与网格数据和原始缓存的DataSource有所不同数据。 2.如果你想改进加载你必须实现和使用分页,所以只有当前页面的数据才能从数据库加载。为此,您可以使用我的下一篇文章作为起点:高级ASPX GridView分页和数据实体 [ ^ ] 1.Is not OK to store in ViewState, because in that case the grid data will be stored twice in ViewState (the GridView object itself with all its rows is stored in view state between postbacks). Also thing about the case when you will add, edit and/or delete from the grid ==>there will be difference from the grid data and your original cached DataSource data. 2.If you want to improve the loading you have to implement and use pagination, so only data from the current page to be loaded from the database. For doing this you can use my next article as starting point: Advanced ASPX GridView Pagination and Data Entities[^]

先生。 Robin 我不知道这是一种正确的方法,但我使用Session代替ViewState。因为ViewState会产生一些问题.. Mr. Robin I don't know this is a correct approach or not but I use Session in place of ViewState. Because ViewState cretae some problems..

更多推荐

ViewState中Datagrid的DataSource?

本文发布于:2023-10-26 18:29:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ViewState   Datagrid   DataSource

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!