如何突出显示日期早于的网格视图列
本文关键字:网格 视图 何突出 显示 日期 | 更新日期: 2023-09-27 18:37:04
我有一个链接到数据源的网格视图。 我有一个名为patched_date的专栏。
如何突出显示日期早于 30 天、60 天等的列。
我不是程序员。 我确实发现了类似的东西,但我不明白。 我可以使用其他代码吗?
好吧,我无法弄清楚。 为什么在编辑日期列时出现"字符串未被识别为有效的日期时间"? 我猜这与它解释数据的方式有关?
我该如何解决这个问题?
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < GridView2.Rows.Count; i++)
{
DateTime date_patched = Convert.ToDateTime(GridView2.Rows[i].Cells[3].Text);
if (date_patched < DateTime.Now)
{
GridView2.Rows[i].Cells[3].BackColor = System.Drawing.Color.Red;
}
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Loop throught your number of rows from gridview data
for (int i = 0; i < GridView2.Rows.Count; i++)
{
//Datetime from your gridview column no.4 (0,1,2,3)
DateTime date_patched = Convert.ToDateTime(GridView2.Rows[i].Cells[3].Text);
//Here you need to modify
//if date_patched older than 30 days and later than 60 days
if(date_patched < DateTime.Now.AddDays(-30) && date_patched > DateTime.Now.AddDays(-60))
{
//do something
GridView2.Rows[i].Cells[3].BackColor = System.Drawing.Color.Red;
}
//if older than 60days
else if (date_patched < DateTime.Now.AddDays(-60))
{
//do something
}
}