Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a coding idea for for Expired Date alert by Red color from a gridview. GridView column name 'Date' and data type 'date'. i need this for code asp.net website. how can i do this correctly. Can i do this with timer clock?? i've tried this one

What I have tried:

C#
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        DateTime date = Convert.ToDateTime(GridView1.Rows[i].Cells[3].Text);
        if (date < DateTime.Now)
        {
            GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.Red;
        }
    }
}
Posted
Updated 1-May-16 7:49am
v4
Comments
Gokulprasad05 30-Apr-16 1:42am    
You doubt is past date are not enter into date field.
Shwrv 30-Apr-16 2:03am    
if i want to do this, with set of timer clock [real time]. how can i do this, any idea?
VR Karthikeyan 30-Apr-16 2:01am    
What is your issue here? explain it.
Gokulprasad05 30-Apr-16 2:14am    
in page load ur datepickername.mindate=date.now()

1 solution

You shall Refresh the GridView data on a periodic manner using Timer

How to refresh GridView automatically using AJAX TimerEverything Technical[^]
Auto Refresh Update GridView In Asp.Net Ajax With Timer[^]

updated solution after OP's clarification:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
             DateTime dt =  DateTime.ParseExact(e.Row.Cells[1].Text, "dd-MMM-yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
             if (dt < DateTime.Now)
                   e.Row.Style.Add("background-color", "red");
           }
       }
 
Share this answer
 
v2
Comments
Shwrv 4-May-16 3:49am    
Date Expired alert from gridView column. need this @KARTHIK
Karthik_Mahalingam 4-May-16 4:14am    
suppose if you have 10 rows and in that 3 rows are expired, then how will you show the alert ?
Shwrv 4-May-16 4:43am    
yes this type rows have expired by current date. its must b dynamically. thnx @KARTHIK
Karthik_Mahalingam 4-May-16 4:55am    
so you need to show the alert message box 3 times?
Shwrv 4-May-16 7:12am    
those dates have expired gridview cell colors changed. or message box can be show for those dates.@KARTHIK

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900