How to store DataGrid in the useless data card from ViewState

xiaoxiao2021-03-06  49

How to store DataGrid in the useless data in ViewState (sometimes it is true) card, everyone knows that DataGrid will store all the data in the table in ViewState, which will cause the viewstate very large; like this forum , The viewstate accounts for 65K, and more waste.

If you just simply set the DataGrid's EnableViewState to false, then many events, such as sorting, change, etc., will not be triggered, then don't you get lost? In fact, in DataGrid, there is a child control for rendering data: system.web.ui.WebControl.dataGridtable, unfortunate, I didn't find its instructions in MSDN, but when I tracked DataGrid, I found it A child control is the above Class (of course, this is what I know later, 嘿嘿). Everyone can take a look at the type of objects in SaveViewState, plus all values ​​in DataGrid.ViewState, will not find data saved in ViewState, then what causes viewstate, what is Data from the data source in ViewState?

The answer is in DataGrid's sub-control (this darkman's existence is really can't stand the feelings). So, if you don't need to store data from these data sources in ViewState (for example, in order to speed up the speed, or custom paging), we only need: DataGrid.Controls [0] .enableViewState = false, is OK.

(Note, you must write this way after the DataGrid generated sub-control, otherwise you can only create emptyware inherited in DataGrid)

-------------------------------------------------- ------------

My use:

I added a sentence at Page_Prender: DataGrid.Controls [0] .NableViewState = false After the initial test did reach the above effect! Feel good!

转载请注明原文地址:https://www.9cbs.com/read-117488.html

New Post(0)