I inherited from GridView to make a custom control that allows the user to make changes to the data on every page without committing those changes to the DB immediately. Only when the user clicks a "Save" button are the changes committed to the DB.
Since fields are re-loaded every time user changes page, changes would not survive the user changing pages. I created a custom object to store user's changes. This object holds the key names/values of the row the changes belong to, and the name/values of the controls that have been changed. I use OnRowDataBound event to show the user changes where they apply. I serialize and save the object with the user changes to and from the viewstate for the object.
My problem now is, how do I tell GridView to update a specific row, i.e. commit the changes to the DB, when all I have are the DataKey pairs for the row. I can find the row number by looking at the GridView's current DataKeys, but that only works for visible rows! If the user has changes on another page, they will not be saved because I can't find the row number using the DataKeys, and UpdateRow requires the row number.
I can't save the row number in my "changes" object and use that because if the data set changes cause the user filters the results in the GridView, then the row number in my "changes" object no longer matches up with the correct row in the GridView.
Please, if you could help I would appreciate it.
Loading
VictorPosted Jan 25, 2010, 3:31 PM
I was hoping to be able to encapsulate the update within the GridView itself instead of having to deal with a datasource outside the GridView. I pass a reference to the page's save button to the GridView. With that button is clicked, the GridView automatically looks in the list of rows with changes and calls UpdateRow row by row. The problem is this only works for visible rows.
Only other thing I can think of is call DataBind on GridView with paging disabled so that all rows are technically visible, find the DataKeys that way and then reset the paging settings to GridView to what it was previously so the notice doesn't actually notice anything different. That seems inefficient to me though.
mihir soniPosted Jan 25, 2010, 3:13 PM
you can specify update command in sqldatasoruce or any method you are using.
[code]
gridview1.datakey
[/code]