protected void TabulkaZakazkyAktivni_DataBound1(object sender, GridViewRowEventArgs e)
 {
    if (gvr.RowType == DataControlRowType.DataRow)
    {
        if (DateTime.ParseExact((gvr.Cells[11].Text), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture) < DateTime.Now)
        {
            gvr.Cells[11].BackColor = System.Drawing.Color.Red;
            Label2.Text = Convert.ToString(gvr.Cells[11].Text);
        }
    }

}

String was not recognized as a valid DateTime.

EDIT 1: Inside gvr.Cells[11] is "2019-05-19 10:19:48.000 "

Line 109: if (gvr.RowType == DataControlRowType.DataRow) Line 110: { Line 111: if (DateTime.ParseExact((gvr.Cells[11].Text), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture) < DateTime.Now) Line 112: { Line 113: gvr.Cells[11].BackColor = System.Drawing.Color.Red;

1 Answers

-1
Marco Salerno On Best Solutions

Try this way:

protected void TabulkaZakazkyAktivni_DataBound1(object sender, GridViewRowEventArgs e)
{
    if (gvr.RowType == DataControlRowType.DataRow)
    {
        if (DateTime.Parse(gvr.Cells[11].Text) < DateTime.Now)
        {
            gvr.Cells[11].BackColor = System.Drawing.Color.Red;
            Label2.Text = Convert.ToString(gvr.Cells[11].Text);
        }
    }
}