日期:2014-05-18  浏览次数:20521 次

如何设置DataTable中的数据输出的颜色
我将数组中的数组读到了DataTable中,并用GridView显示了出来,可我现在需要将一些符合特定条件的行以不同颜色输出,该在那个环节做调整?

------解决方案--------------------
用模板列
在ItemDataBound内编程
------解决方案--------------------
这个的在GridView的行绑定时进行判断
RowDataBind
------解决方案--------------------
模板列里面有属性可以设
------解决方案--------------------
在itemdatabound事件中:
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{ e.Item.Attributes.Add( "onmouseover ", "currentcolor=this.style.backgroundColor;this.style.backgroundColor= 'ceeaff '; ");
e.Item.Attributes.Add( "onmouseout ", "this.style.backgroundColor=currentcolor ");
}