Thursday 2 January 2014

How to fix issues where e.Row.Cells returns empty string while accessing gridview rows

 Watch this example on YouTube

REPLACE

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string test1 = e.Row.Cells[0].Text;
            }
        }
WITH
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lb = (Label)e.Row.Cells[0].FindControl("Label1");
                string test2 = lb.Text;

            }
        }

1 comment: