views:

919

answers:

3

When adding an EditItemTemplate of some complexity (mulitple fields in one template), and then parsing the controls from the RowUpdating event, the controls that were manually entered by the user have no values. My guess is there is something going on with when the data is bound, but I've had instances where simply adding and attribute to a control in codebehind started the behavior and removing that code made the code work. As a work-around, I can Request(controlname.UniqueId) to get it's value, but that is rather a hack.

Edit When I access the value like so

TextBox txtValue = gvwSettings.SelectedRow.FindControl("txtValue") as TextBox;

the text box is found, but the .Text is not the user input.

A: 

You should be able to use the GridViewUpdateEventArgs to retrieve the inputted value, for example:

TextBox txtValue = gvwSettings.SelectedRow.FindControl("txtValue") as TextBox;

I have used that syntax before and it works like a charm.

Elijah Manor
+1  A: 

Did you turn off ViewState? Did you add control programmatically in the template? If so, did you create them at the correct stage?

leppie
A: 

Moved post-back data-bind to Page_Init

Greg Ogle
No, that is too early :)Anywhere from Load to PreRender is ok IIRC. I prefer to stick to Load.
leppie
Are you maybe re-binding on the postback?
leppie
from http://msdn.microsoft.com/en-us/library/ms178472.aspxDuring load[Page Load], ...control properties are loaded [from]... control state. So, my theory is there is an issue with the gridview not knowing about its controls 'cause they're not there yet.
Greg Ogle