jeudi 28 mai 2015

'Find and Save' functionality not working (ASP.net, GridView, DataTable)

First time poster, long time lurker. I am having some trouble with my ASP.NET page, and I hope someone can help me resolve my issue.

Basically, I have a bunch of checkboxes in a gridview, and two buttons: a 'find' button, and a 'save' button. The 'find' can set the value of the checkbox, but if a user unchecks it, I want to capture that change when the user hits 'save'.

The 'find' button does the following:

  1. Builds the DataTable in code and assigns it to the Page's class variable 'infoTable'.
  2. Does a string comparison between a textbox (defined in aspx) and names in a List object
  3. If a name match is found, it uses that to search a list of transactions.
  4. If a transaction match is found, populates (Rows.Add) the infoTable with transaction info (among the data is a bool (isPaid) that started this journey, ill get to that...).
  5. Builds a GridView (also a Page class variable) by using the infoTable as a DataSource, binds it, sets a RowDataBound eventhandler, etc..
  6. The RowDataBound event handler is used to add checkboxes to the last column in the GridView. The status of these checkboxes will be checked or not depending on the status of 'isPaid'.

All of that works. Here is where it gets tricky/confusing:

After I hit the save button, PostBack occurs and both DataTable and GridView empty (Rows.Count is 0 at this point for both). ViewState appears to be lost before I get a chance to loop through the GridView rows to determine the checkbox values.

EnableViewState in the html/.aspx is set to true, but it doesn't appear to help. I've tried building GridView by using (DataTable)ViewState["datatable"] as a datasource. This doesn't help either.

At the end of it all, I just want to capture the status of those checkboxes, changed by user interaction or not, by hitting the 'Save' button.

I found some other articles, but a lot of them haven't worked when I tried implementing the various fixes.

This one seems to be the closest that describes my issue, and the code is structured similarly, but I don't quite understand how to implement the fix: GridView doesn't remember state between postbacks

Any help would be appreciated. Thank you in advance!




Aucun commentaire:

Enregistrer un commentaire