In the DataGrid control, data is generally displayed only in bound columns or template columns.
When writing the event processing method of the DataGrid control (the control name is dg1), you usually want to obtain the data of a certain column of the data item.
Except for the SelectedInexChanged event, the parameters e of other event processing methods are instances of the DataGridCommandEventArgs class. Through the e instance, you can obtain the data in the data item that triggered the event.
1. Get the data in the bound column
1) In non-editing state, or the data item is in editing state but the bound column is read-only
e.Item.Cells[Column Index].Text
2) If the bound column is in the editing state, it will be displayed as a TextBox control.
((TextBox)(e.Item.Cells[Column Index].Controls[0])).Text
2. Get the data in the template column. One or more controls can be placed in the template column (right-click "Edit Template" menu) , these controls can bind data in the data source. To obtain data bound to a control in the template column, you must first know the id of the control, and then use the FindControl method to obtain a reference to the control.
((Control type)(e.Item.Cells[column index].FindControl("controlid"))).Control's properties
eg: ((CheckBox)(e.Item.Cells[3].FindControl("cbSex"))).Checked