views:

159

answers:

2

I have a DataGrid, with an ItemTemplate that has an image and label. In the EditItemTemplate the label is replaced by a textbox. My problem is that the edit template only shows when I click the Edit button the second time. What gives?

+1  A: 

Make sure you check for Page.IsPostback before binding your datagrid. It may be the case that you are binding during every page load.

If Not Page.IsPostBack() Then
    DoDataBinding()
End If
EndangeredMassa
A: 

Make sure you're re-binding the DataGrid after setting the EditItemIndex property.

Edit: Agreed with Massa. Best practice is to move your databinding into a separate method and call it first on the first page load, and again after setting EditItemIndex.

Raelshark