I've used rowdatabind code in gridview for expired date alert by colored row those dates already have expired. My table's column ExpDate type is "date". its works well but now the problem is- when any row cell become null, its given error. my gridviewrowDatabound code is-
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
DateTime date = Convert.ToDateTime(GridView1.Rows[i].Cells[8].Text);
if (date < DateTime.Now)
{
GridView1.Rows[i].BackColor = System.Drawing.Color.Red;
GridView1.Rows[i].Visible = true;
}
else
{
GridView1.Rows[i].Visible = false;
}
}
}
Showing error : "String was not recognized as a valid DateTime" , for code line- " DateTime date = Convert.ToDateTime(GridView1.Rows[i].Cells[8].Text);" now what can i do. anyone can give me an idea, please!!