GridView loses data during postback

后端 未结 5 1223
我在风中等你
我在风中等你 2021-01-12 09:22

I have an aspx.Page containing a gridview. The gridview is bound in code behind to a datasource only when no postback takes place and has enableviewstate = true (The page to

5条回答
  •  长发绾君心
    2021-01-12 10:03

    This is by design. This data is not stored anywhere natively from page load to page load. You will need to perform one of the following 3 tasks:

    1. Store the data in ViewState (not necessarily recommended if the data is large)
    2. Store the data in a Session object (same story, large data equals bad memory usage)
    3. Make a return trip to rebind the data each time the page loads (breaks down if there is too much activity on the database or if the query is slow)

    My preference is to make return trips to the database when I need to and keep my SQL tuned for performance. Heavy page loads are annoying, and too much session memory can cause slowing on the server. I believe you can also store this data in cache, but I've never attempted it so I don't know what the limitations or capabilities there are.

提交回复
热议问题