Recommended Free Tools
For a BoundField or automatically generated GridView column, read the cell’s Text property: MyGridView.Rows[rowIndex].Cells[columnIndex].Text. For a TemplateField, retrieve the control inside the row with FindControl; for a database key, use DataKeys instead of a displayed cell.
Read a BoundField or automatically generated column
Get the row from the GridView’s Rows collection, then read the cell at the column’s zero-based index:
GridViewRow row = MyGridView.Rows[rowIndex];
string value = row.Cells[columnIndex].Text;
Microsoft documents Text as the way to retrieve a field value from a BoundField or automatically generated field column: GridViewRow documentation. Both indexes are positional: rowIndex identifies a displayed row, and columnIndex identifies a cell in the rendered column order.
Read the selected GridView row
Use SelectedRow when the GridView has a selected row, and check for null before reading it. Microsoft documents that SelectedRow is null if no row is selected: SelectedRow documentation.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
GridViewRow row = MyGridView.SelectedRow;
if (row != null)
{
string value = row.Cells[columnIndex].Text;
}
This reads the displayed cell value from the selected row. In a selection event handler, the selected row is available through SelectedRow; use a child control or DataKeys instead if the value you need is not plain cell text.
Read a value from a TemplateField
A TemplateField can contain controls rather than a plain text cell. Find the control by its ID within the row and read the property that represents its value:
Rank #2
GridViewRow row = MyGridView.Rows[rowIndex];
Label label = (Label)row.FindControl("NameLabel");
string name = label?.Text;
CheckBox check = (CheckBox)row.FindControl("ActiveCheckBox");
bool isActive = check?.Checked ?? false;
For example, a label exposes its text through Text, while a checkbox exposes its state through Checked. The null-conditional and null-coalescing operators avoid dereferencing a missing control. If the template binds a value directly rather than placing it in a named control, ASP.NET may represent it as a DataBoundLiteralControl; read that control’s Text property. Microsoft describes both control lookup and this literal-control behavior in its GridViewRow documentation.
Use DataKeys for a database key
For a primary key such as ProductID, configure DataKeyNames and read the corresponding value from DataKeys. This avoids relying on a visible column position:
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →<asp:GridView ID="MyGridView" runat="server" DataKeyNames="ProductID" />
object productId = MyGridView.DataKeys[rowIndex].Value;
DataKeyNames identifies the key field or fields, and DataKeys holds key values for displayed rows. For a selected row, use its index to obtain the matching key; Microsoft’s ASP.NET tutorial demonstrates retrieving a selected product’s ProductID from DataKeys: Adding a GridView Column of Checkboxes.
Choose the right value source for the event
The right property depends on what the value represents and when the handler runs:
Rank #4
- Rendered field text: use
row.Cells[index].Textfor aBoundFieldor autogenerated column. - Template control value or state: use
FindControl, then read the control’s relevant property. - Primary key: use
DataKeyswithDataKeyNamesconfigured. - Underlying bound object: use
GridViewRow.DataItemin theRowDataBoundlifecycle window. It is not a general-purpose property to rely on at any point in a postback.
Microsoft documents DataItem availability in connection with RowDataBound and explains cell and control access in the GridViewRow documentation. If code runs later, such as in an ordinary postback handler, use the rendered cells, template control, or key collection as appropriate rather than assuming the original data item remains available.
Account for column order and framework lifecycle
Cells[columnIndex] follows rendered order, so inserting, removing, or rearranging columns can make a positional lookup point to a different field. A named control in a TemplateField or a value in DataKeys is generally more resilient when the display layout changes. Examples using DataItem depend on the ASP.NET Web Forms lifecycle; run that access in RowDataBound rather than treating it as available throughout the page lifecycle.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsQuick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

