public static bool ColumnExists( this DataRowView rowData, string fldToCheck)
{
return rowData.Row.Table.Columns.Contains(fldToCheck);
}
Normally, you would use it on RowDataBound event, e.g:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView rowData = e.Row.DataItem as DataRowView;
string fldToCheck = "MyFieldName";
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (rowData.ColumnExists(fldToCheck) ...
Related posts:
Find GridView Column Index
Set DataRow Values and Other ASP.NET GridView Tips