Accessing editable controls in DataGrid update handler

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having a problem accessing changed values in TextBoxes returned via the OnUpdaterow event. Using C# I access the control using: string _txtAmt = ((TextBox)e.Item.FindControl("txtAmount")).Text

Upon inspection of _txtAmt, the old (pre-edited) value of the textbox is returned versus the changed (edited) value. Using the FindControl method should work, right? I see a lot of examples using an indexer into the e.Item.Cells[n].Controls[n] to retrieve the control but couldn't figure out which indexer was correct to reference the textbox. If I used the 0th element, I received a literal control rather than the textbox and couldn't cast it into what I needed to read the value.

Would appreciate any help
EddieG
 
Hi,

is it sure you are not rebinding the grid on postback accidentally so that
it would mix things up. E.g bind the grid inside IsPostBack check In
Page_load and then only when necessary by the logic (when grid needs to be
rebind i.e when data has changed)
 
Back
Top