I have a List called dayList which has 12 dates in it. I am trying to Bind this List to a GridView Column.
GridView2.DataSource = dayList;
GridView2.DataBind();
for (int i = 0; i < dayList.Count; i++)
{
Label lbldate = (Label)GridView2.Rows[i].FindControl("lblgriddate");
lbldate.Text = Convert.ToString(dayList[i]);
}
}
I am getting Object reference not set to an instance of an object error at:
lbldate.Text = Convert.ToString(dayList[i]);
Is it because there are no rows in the GridView? But shouldnt GridView automatically add rows just like when we bind GridView Column with DataTable?