根据系统日期更改GRIDVIEW的单元格颜色 [英] change cell color of GRIDVIEW based on system date
本文介绍了根据系统日期更改GRIDVIEW的单元格颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,我的项目基于asp.net c#
正在使用 GRIDVIEW .因为我有一个列名Expirydate
Dear Friends, my project is based on asp.net c#
am working on GRIDVIEW. in that i have a column name Expirydate
for example :
============
22\08\2012
22\08\2013
15\09\2012
16\06\2012 - This date is expired according to current system date.
因此,我的要求是,如果ExpiryDate小于今天的日期,则应在 GRIDVIEW 中将该粒子单元格的 THE 背景颜色更改为红色.
请帮忙,
感谢 ADVANCE .
So my requirement is, if the ExpiryDate is less than todays date, THE background color of that partciular cell should be changed to red color in GRIDVIEW.
Please help ,
Thanks in ADVANCE.
推荐答案
尝试一下
if(DateTime.Compare(Date1,Date2))
{
GridView1.Rows[index].Cells[index].BackColor = System.Drawing.Color.Red;
}
问候
Kunjammu
Regards
Kunjammu
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
DateTime date = Convert.ToDateTime(GridView1.Rows[i].Cells[0].Text);
if (date < DateTime.Now)
{
GridView1.Rows[i].Cells[0].BackColor = System.Drawing.Color.Red;
}
}
}
这是代码.它为我工作.像您一样更改单元格索引
问候
Kunjammu
This is the code. its working for me. change the cell index as u like
Regards
Kunjammu
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime Stock =
Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem,
"Column_Name"));
if(Stock > DateTime.Now)
e.Row.BackColor =System.Drawing.Color.Red;
}
}
这篇关于根据系统日期更改GRIDVIEW的单元格颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文