如果日期小于其他列单元格,如何显示gridview单元格的颜色 [英] How to display color for gridview cell if date is less than other column cell

查看:112
本文介绍了如果日期小于其他列单元格,如何显示gridview单元格的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想在asp.net gridview单元格中显示背景颜色。



例如:

我有两个名为DateFrom和DateTo的列。

Hi everyone,

I want to display background color in in asp.net gridview cell.

For example:
I have two columns with name DateFrom and DateTo.

DateFrom(2nd column in GridView)
DateTo(3rd Column in GridView)



如果datefrom小于Date,则应为红色。

如果DateTo大于DateFrom,它应该是是绿色


if datefrom is less than Dateto it should be red.
and if DateTo is greater than DateFrom it should be GREEN

item.Cells[1].BackColor = Color.FromName("#FF6A6A")RED color;
item.Cells[2].BackColor = Color.FromName("#77FF77")Green Color;



请帮助,谢谢。


Please help, Thanks.

推荐答案

你需要使用GridView的 RowDataBound ,例如:

You need to use RowDataBound of GridView, something like:
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{ 
   DataControlRowType rtype = e.Row.RowType;  
   if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
       && rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
       && rtype != DataControlRowType.Pager)  
   { 
      // Control specific

      TextBox tb1 = (TextBox)e.Row.FindControl("myDate1");
      TextBox tb2 = (TextBox)e.Row.FindControl("myDate2");
      
      // Your logic for data of tb1 & tb2.
      // Your setting of the color for defined column. 
      
   }
}


这篇关于如果日期小于其他列单元格,如何显示gridview单元格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆