Accessing editable controls in DataGrid update handler

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
 
T

Teemu Keiski

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top