Datagrid问题 我设计一个Datagrid,我想要根据某一个列的值来判断行的文字的颜色,比如一个列,有run,stop,error,其中run所在的行文字是绿色的,stop是红色的,error是黄色的,程序如何编写,背景色不变? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Datagrid 的名字后 打.然后 通过提示 看看 哪个属性是设置颜色的 把那个给改一下 就好了 protected void MyDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='LightGoldenrodYellow'") ; e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'") ; e.Item.Style["cursor"] = "hand"; e.Item.ForeColor=Color.Blue; if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=30 && Convert.ToInt32(e.Item.Cells[6].Text.ToString()) <60) { e.Item.ForeColor =System.Drawing.Color.Green; } if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=60 && Convert.ToInt32(e.Item.Cells[6].Text.ToString()) <90) { e.Item.ForeColor =System.Drawing.Color.Indigo; } if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=90 && e.Item.Cells[6].Text.ToString()!=null) { e.Item.ForeColor =System.Drawing.Color.Red; } } } 和四楼差不多,在ItemDataBound事件里面,判断item的值,设置不同颜色。 可以绑定每一列的Color属性。这样不用编代码,可以直接根据数据库中的数据改变颜色。 同意楼上的,我门可以直接在run,stop,error的值设成颜色的值,然后赋予blackcolor antiking(Q狼E行-吹雪留香一点红,孤城寻欢花满楼) 这个方法好我就是这样用的 你也可以把不同的列的值设成这样: <font color=red>value</font> 在asp.net项目中,将网页直接保存成pdf文件 猴子吃桃问题 求解(代码) 求初学ASP.NET和C#有帮助的书籍和视频教程 超链接CSS 烦死掉` 新手问题,treeview如何实现点击加减号不刷新页面,点击节点才刷新页面 IEWebControls 有NET2.0版的下载吗 弹出的页面是框架页面,如何关闭这个框架页面的时候,刷新原来的页面? 急盼高手解答,客户端脚本如何引用用户控件内的元素? 奇怪的错误 高手请进,一个困扰了我几天的问题!(SOS) 这种问题怎么解决?提示框。 sqlserver数据库中,日期的默认值格式怎么设置?
然后 通过提示 看看 哪个属性是设置颜色的 把那个给改一下 就好了
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='LightGoldenrodYellow'") ;
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'") ;
e.Item.Style["cursor"] = "hand";
e.Item.ForeColor=Color.Blue;
if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=30 && Convert.ToInt32(e.Item.Cells[6].Text.ToString()) <60)
{
e.Item.ForeColor =System.Drawing.Color.Green;
}
if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=60 && Convert.ToInt32(e.Item.Cells[6].Text.ToString()) <90)
{
e.Item.ForeColor =System.Drawing.Color.Indigo;
}
if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=90 && e.Item.Cells[6].Text.ToString()!=null)
{
e.Item.ForeColor =System.Drawing.Color.Red;
}
}
}