protected void myDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Do something with the data grid item } }
protected void myDataGrid_EditCommand(object source, DataGridCommandEventArgs e) { myDataGrid.EditItemIndex = e.Item.ItemIndex; // Bind the data grid again to show the edit fields myDataGrid.DataBind(); }In this example, we're handling the DataGrid's EditCommand event and setting the EditItemIndex property to the index of the item that triggered the event. This will cause the data grid to display the edit fields for that item. We then call DataBind() to refresh the data grid and show the updated view. Package library: System.Web.UI.WebControls