You can access BoundFields through e.Row.Cells[index].Text :
foreach (GridViewRow row in GridView.Rows) { string accessType = row.Cells[3].Text; }
However, I would use a RowDataBound instead of an additional foreach .
Here is the RowDataBound event that is RowDataBound for each row in the GridView when it was bound to the database. Assuming the DataSource is something like a DataTable :
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBox check = (CheckBox)e.Row.FindControl("CheckBox1"); CheckBox check2 = (CheckBox)e.Row.FindControl("CheckBox2"); DataRow row = ((DataRowView)e.Row.DataItem).Row; int accesType = row.Field<int>("AccessType"); check.Checked = accesType == 1; check2.Checked = accesType == 2; } }
Tim schmelter
source share