Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi i have date record in my database.when i want to show the records in datagridview, i want to change the color of some rows that the date record of them is as the same as date of today.how can i do that?
thanks alot
Posted

Here i am checking 2 column as datetime column. Pls change as per you grid design

C#
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)    {
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
    if (Convert.ToDateTime(e.Row.Cells[1].Text)==DateTime.Now)
    {
     e.Row.BackColor = System.Drawing.Color.Red;
    }
 }
}
 
Share this answer
 
Hi,
1.using System.Drawing;
2.write code in this event
C#
protected void gvReminder_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       try
       {
           if (e.CommandName == "subject")
           {
              
               int Index = Convert.ToInt32(e.CommandArgument);
               ViewState["ReminderId"] = gvReminder.Rows[Index].Cells[1].Text;  btnDelete.Visible = true;
               view();
               GridFillReminderDetails();
               gvReminder.Rows[Index].Cells[0].ForeColor = Color.Red;
               gvReminder.Rows[Index].Cells[1].ForeColor = Color.Red;
               gvReminder.Rows[Index].Cells[2].ForeColor = Color.Red;
               ((LinkButton)gvReminder.Rows[Index].Cells[3].Controls[0]).ForeColor = Color.Red;
               gvReminder.Rows[Index].Cells[4].ForeColor = Color.Red;
           }
       }
       catch
       {
       }
   }
 
Share this answer
 

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