Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

asp.net - does gridview save data in viewstate?

hi i bind a DataTable to a gridview. i want to use the DataTable in some postback event, and ii want to use viewstate. does gridview save data in viewstate? if no what is the best way to do this.

(full story : i have a custom gridview derived from standard asp.net gridview, and i put a button in header to export data to excel, i want to use data saved in viewstate to export to excel)

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The short answer is yes, information shown in the GridView, much like the current state of any control, is stored in ViewState. However, I do not think it is easy, if even possible, to get to this data yourself out of the ViewState collection that is available to WebControls. Instead, ASP.NET populates values from ViewState before running event handlers in the lifecycle, so if you interrogate your GridView object server-side in a handler, you should see the current values of the cells.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...