Gridview RowDataBound - extract data from a field
Use DataItem of the GridViewRow instead of DataBinder.Eval to get the underlying datasource:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit))
{
DataRow row = ((DataRowView)e.Row.DataItem).Row;
String name = row.Field("Name");
// OR
name = row[1];
// String is a reference type, so you just need to compare with null
if(name != null){/* do something */}
}
}
Comments
Post a Comment