Create an expired date alert on a Gridview in ASP.NET in C#

Asked

Viewed 89 times

-1

I am doing a final project, where a record of task, description and date is made. But I am unable to put a warning/alert/message on the screen to warn the user that a task is expiring. I am programming for web in ASP.NET, C# and the Database is SQL Server Express. I tried with this code, but nothing happens.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {           
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    DateTime dt = DateTime.ParseExact(e.Row.Cells[3].Text, "0:dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                    if (dt < DateTime.Now)
                        e.Row.Style.Add("background-color", "red");
                }               
        }

I would like to leave it that way when a system date coincides with the same computer, not necessarily identical but with some outline, or a background color in the line of the Gridviewer for highlight.

  • 1

    Please post the code in text. It is difficult to test with just one photo as an example

  • 1

    I put the code in text.

  • iDate needs to be a string with a date. If you want to use computer time you can use Datetime.Now or Datetime.Utcnow.

1 answer

0

The comparison of dates is never performed because of Response.Redirect.

You can remove the redirect code and replace the IF of the dates by the code below to check the comparison of the dates.

if(dt1.Date > dt2.Date)
{
  Response.Write("Tarefa expirando.");
}
else
{
  Response.Write("TESTE");
}
  • Thank you tvdias, for lack of attention my went unnoticed the command Response.Redirect. Finally, I put according to your suggestion, but gave another error: "The string was not recognized as a valid Datetime".

  • Unfortunately it didn’t work. I changed the code, but it still doesn’t work either. Thanks anyway tvdias.

  • tvdias, I did it! I just put it in the right Gridviewer method. I had to remove Response.Redirect. Thank you so much for your help!!!

  • In this case it is interesting to create an answer to your own question explaining in detail the solution and then accepting it. @Israelcostaesilva

Browser other questions tagged

You are not signed in. Login or sign up in order to post.