user912272
user912272

Reputation: 23

asp.net gridview: reading values and persisting state

I have a gridview that is databound to a list of custom objects. On the client side, the user can enter a price value in a textbox and click on a checkbox for every row in the gridview. The gridview supports pagination and contains dozens of pages. When data is changed in the gridview I don't necessarily want to change entries in the database because the user could end up cancelling out of the page, but I do want to remember (for now) what was check on other pages.

I'm trying to figure out how to read all the values across all the pages in the gridview when the user clicks submit. I could setup event handlers for the textboxes and checkboxes but I still need to store the modifed list of custom objects. In ASP, is this normally done in the application cache or should I be storing stuff in the viewstate?

Upvotes: 2

Views: 391

Answers (1)

Ed B
Ed B

Reputation: 6054

You can store the values in ViewState or Session. When it's time to update, you update the DB.

It's not normally done in the application cache since data should only persist for the user's session.

i.e. Load up your list of Products & Bind it to the gridview. Also store the Products to your Viewstate. When it's time to add,update or delete a product, you make the changes to the Products object in ViewState.

On your SaveClick Event you read the products from ViewState and update the DB.

Just be sure to check for concurrency issues.

Upvotes: 1

Related Questions