ViewState中Datagrid的DataSource? [英] DataSource of Datagrid in ViewState?

查看:79
本文介绍了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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆