Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
903
ClickCellButton and e.Cell.Row.DataKey
posted

I have a grid where the contents are from a parameter driven SQLDataSource and so I am rebinding in InitializeDataSource, PageIndexChanged and SortColumn.  I have a cell button which takes an application specific action. 

e.Cell.Row.DataKey in the ClickCellButton handler returns the wrong value.  It looks like because no rebinding is done when ClickCellButton is triggered the grid dataset is incorrect.  I have found that if I page the grid before I click the cell button (thus causing a rebind) then e.Cell.Row.DataKey returns the right value.  I have tried doing a rebind in Page_Load if I detect that the grid was the cause of the postback.  e.Cell.Row.DataKey then returns the right value but I now sometimes get Invalid postback or callback argument." . I have read that this can be caused by unnecessary postbacks.

ViewState is enabled.  What should I be doing so that I get the right value from e.Cell.Row.DataKey?