In VS-2003 ASP.Net using VB.net.
The DataGrid contains a property called
EditItemIndex, which specifies what row of the DataGrid is the
row being edited. The DataGrid numbers its rows starting at 0. By default, the DataGrid is not editing any
row, so the EditItemIndex, by default, has a value of
-1. Since we want to mark a row for editing when its "Edit"
button is clicked, we simply need to write some code in the
EditCommand event handler, which is the DataGrid
event handler that is fired when the
EditCommandColumn control's
"Edit" button is clicked. This event handler
simply needs to set the EditItemIndex property to the row whose "Edit" button was clicked and then rebind the
DataGrid data (by calling BindData() or your chosen function name). The code for this event handler can be seen below:
-
-
Sub dgProducts_Edit(sender As Object, e As DataGridCommandEventArgs)
-
dgProducts.EditItemIndex = e.Item.ItemIndex
-
BindData()
-
End Sub
-
To wire this event handler up to the EditCommand event, simply specify this in your DataGrid control, like so:
-
-
<asp:DataGrid id="dgProducts" runat="server"
-
...
-
OnEditCommand="dgProducts_Edit"
-
... >
-
-
<Columns>
-
...
-
</Columns>
-
</asp:DataGrid>
-
hope it helps...