环境:VS2008,C#
问题:
从数据库中提取表信息填充到单元格内,数据表里有条时间记录(格式:YYY-MM-DD)读取到GridView后,我想通过判断当前时间改变日期字体颜色 或者单元格背景色,比如,表中时间>当前时间,显示为蓝色字体,否则显示为红色字体,或者修改单元格背景色为红色或者蓝色,请兄弟姐妹告诉怎么实现
问题:
从数据库中提取表信息填充到单元格内,数据表里有条时间记录(格式:YYY-MM-DD)读取到GridView后,我想通过判断当前时间改变日期字体颜色 或者单元格背景色,比如,表中时间>当前时间,显示为蓝色字体,否则显示为红色字体,或者修改单元格背景色为红色或者蓝色,请兄弟姐妹告诉怎么实现
解决方案 »
- 关于checkboxlist样式的问题
- 正则表达式抓取table数据的内容
- 很急的问题,怎么都连不上数据库~~~在线求教
- 我真搞不懂那些搞IT的人为什么喜欢自我贬低?
- **************能否从后台控制treeview的选中节点,并使选中的(多个)节点变色?详情请进。急需,多谢!
- aspnet_wp.exe被回收的问题,你们碰到过吗??(倾我全部可用分求解)
- 简单问题:在页面中弹出消息框的js该什么写啊?
- 一系列问题。大家来讨论!同时也欢迎大家提问,共同解决,共同进步!谢谢!
- sqlConnection的设置问题
- 如何在用户在输入资料时自动将小写转换成大写?
- 洒最高分,再问个ASP.NET MVC 方面的问题
- 如何使用executereader()返回count(*)的值并用label显示值
{
if(时间>系统时间){
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF';");}
else
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor =currentcolor");
}
}
e.Row.Attributes.Add("this.style.backgroundColor", "#00A9FF");}
</asp:GridView>public class Demo
{
public string ID { set; get; }
public DateTime Time { set; get; }
} protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.GridView1.DataSource = new System.Collections.Generic.List<Demo>()
{
new Demo(){ ID="S001", Time=DateTime.Now.AddDays(-1)},
new Demo(){ ID="S002", Time=DateTime.Now.AddDays(1)},
new Demo(){ID="S003", Time=DateTime.Now.AddDays(-2)},
new Demo(){ID="S004", Time=DateTime.Now.AddDays(2)},
new Demo(){ID="S005", Time=DateTime.Now.AddHours(2)},
new Demo(){ID="S006", Time=DateTime.Now.AddHours(1)},
};
this.GridView1.DataBind();
}
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Normal)
{
DateTime time = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "Time"));
if (time > DateTime.Now)
{
e.Row.Cells[1].Attributes.Add("style", "background:blue;");
}
else
{
e.Row.Cells[1].Attributes.Add("style", "background:red;");
}
}
}
}