pyram
pyram

Reputation: 935

GridView onrowediting event values lost

im working on asp.net with c#, and I have a gridview with textboxes and dropdownlists. I have data loaded from an sql database into the gridview with the GridView1_RowDataBound.

I have a linkbutton which once is clicked brings the GridView1_RowEditing event, this enables the whole row for editing. But when this happens, all the data for the corresponding row is gone. All the textboxes and dropdownlists have no value.

What can I do, so the values stay on the controls once the RowEditing event is fired?

Upvotes: 0

Views: 327

Answers (1)

Frazell Thomas
Frazell Thomas

Reputation: 6111

Be sure that you are not data binding after the control has been loaded. Be sure that you are populating the data for your control only after making sure the page is not being posted.

If Not Page.IsPostBack Then
'Populate control
End If

Otherwise the control data will be reset as viewstate data is loaded on PreInit before the Load event is called.

Also, ensure you have viewstate enabled unless you are repopulating the control data.

Upvotes: 1

Related Questions