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

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.