根据到期日更改Gridview单元格颜色

问题描述:

我的网格视图法作为POP UP



如何从当前日期更改网格视图单元格(到期日期)的背面颜色?

My Grid View Act as a POP UP

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

Hello Krishna,



您可以在RowDataBound事件处理程序中执行此操作。以下代码段可以帮助您入门。

Hello Krishna,

You can do so in RowDataBound event handler. The following snippet should get you started.
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,


您可以在gridview的RowDataBound事件中执行此操作,如下所示:

You can do that in RowDataBound event of gridview like this:
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..:)