Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Grid View Act as a POP UP

How can i change the Back color of grid view Cell(Expiry Date) from Current Date ?
Posted

Hello Krishna,

You can do so in RowDataBound event handler. The following snippet should get you started.
C#
protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
    
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        int result = DateTime.Compare(e.Row.DataItem("DATE_COLUMN_NAME"), Date.Now);
        if ( result < 0)
            e.Row.Cells[0].BackColor = Color.Red;
    }
}

Regards,
 
Share this answer
 
You can do that in RowDataBound event of gridview like this:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       if(your condition)
       {
         e.Row.Cells[Index].BackColor = System.Drawing.ColorTranslator.FromHtml("#000");
         e.Row.Cells[Index].ForeColor = System.Drawing.Color.White;
       }
    }
}

Regards..:)
 
Share this answer
 
v2

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