比如说我有一个dataGrid 现在所有行的颜色都一样我想对某一列做一个特殊的要求,比如说time这一列,想让time列中的值是今天时间的为红色,明天的为绿色,以后的保持原来的颜色
这个能不能实现啊,各位大虾们帮我看看啊。
这个能不能实现啊,各位大虾们帮我看看啊。
解决方案 »
- js调用webservice的问题~~~~
- .net修改文件夹文件权限的问题!
- GridView OldValues为空的问题?在线等!!!
- asp.net+ajaxpro2.0+javascript Session存储用户名失败 --不能读写 急。。。。
- 大家来谈谈在asp.net中使用HTC这种方式如何呢?
- 关于提交确认的问题
- 谁可以备注如下代码?
- vs2003 和 iis问题
- 奇怪,我在htm测试好的js验证代码,在aspx下都不管用了
- 如何读取表A中四个列的值并赋值给四个string?
- 判断用户是否连接1.aspx.如果已经有此连接,再次连接则无效。 或者关闭以前的连接.新连接生效.
- 为什么只读取ID 值?
foreach(DataGridItem dgi in this.dg.Items)
{
for(int i=0;i<dgi.Cells.Count;i++)
{
if(Convert.ToDateTime(dgi.Cells[15].Text)>= Convert.ToDateTime(System.DateTime.Now.AddDays(-1)))
{
dgi.Cells[i].BackColor = Color.Red;
}
} }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//在这里处理
}
}
//如果TitleOfCourtesy列的值为"Mr."则设置该行的背景色为蓝色
if((e.Item.Cells[3].Text)=="Mr.")
e.Item.BackColor=Color.Blue;
//如果TitleOfCourtesy列的值为"Ms."则设置该行的背景色为红色
if((e.Item.Cells[3].Text)=="Ms.")
e.Item.BackColor=Color.Red;
当然不会有2005 dataview的事件
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//判断是否今天
if(e.Row.cells["datatime"]==datatime.now.year+"-"+datatime.now.month+"-"+datatime.now.day)
//添加背景色
e.Row.Attributes.Add(this.style.backgroundColor=red)
}
}
就是上面这个原理了..以上代买为手写..请自己测试后在写了用
{
if (e.Item.ItemIndex!=-1)
{
//在这里处理
}
}
<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center" ForeColor="White"></HeaderStyle>
<ItemTemplate>
<input type="hidden" id="SelectedID" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "OrderId")%>' NAME="SelectedID"/>
</ItemTemplate>
</asp:TemplateColumn>绑定了一列
{
if (state.Equals("1"))
{ if (!e.Row.Cells[14].Text.Equals("") && !e.Row.Cells[14].Text.Equals(" "))
{
e.Row.Cells[14].Text = Convert.ToDateTime(e.Row.Cells[14].Text).ToString("yyyy-MM-dd");
if (dal.Expired(this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString()))
{
e.Row.BackColor = System.Drawing.Color.FromName("#FF99CC");
}
}
}
}
如果你是想time这一个单元格变色.foreach(DataGridItem dgi in this.dg.Items)
{
if(Convert.ToDateTime(dgi.Cells[15].Text)>= Convert.ToDateTime(System.DateTime.Now.AddDays(-1)))
{
dgi.Cells[15].BackColor = Color.Red;//time所在的单元格
}
} }代码放在你的数据绑定之后
或者
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemIndex!=-1)
{
if(Convert.ToDateTime(e.Item.Cells[15].Text)>= Convert.ToDateTime(System.DateTime.Now.AddDays(-1)))
{
e.Item.Cells[15].BackColor = Color.Red;//time所在的单元格
}
}
}
跟你第一列 绑定OrderId有什么关系呢?你是哪一列绑定的time 就判断哪一列啊...