一个表里面有个字段是颜色数据,绑定到datagrid,如果碰见有颜色数据的就显示颜色,没有的就都是默认,这样如何去做?最好有简单代码
解决方案 »
- 有没有什么代码让做出来的网站兼容性更好
- .net 幻灯片的制作
- 如果 sql的 like 在两个%之间为空,搜索出来的是全部数据,还是没有数据?
- 111.abc.com、222.abc.com,二级域名下共享窗体验证如何设置?
- theForm._EVENTTARGET为空或不是对象
- 我正在调试程序,假设程序没有错,别人也正在试用。
- 大批量数据的修改(WEB下)
- 求助一个URL问题
- 请问像论坛这样的treeview怎么传值到其他页面,显示相应的页面
- 1
- [80分相送,简单问题]三层架构中在逻辑层中如何引用session
- 请问大家在网页里用 office web component 可以更新数据库吗?
{
ListItemType itemType = e.Item.ItemType;
e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
if (itemType == ListItemType.Item )
{
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
}
if( itemType == ListItemType.AlternatingItem)
{
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
}
}
可以先判斷一次
true的話就添顔色
protected string SetColor(string str)
{
return "<font color='red'>"+str+"</font>"
}
DataGrid内使用模板列
比如
<ItemTemplate>
<asp:Label runat="server" Text='<%# Setcolor(DataBinder.Eval(Container, "DataItem.Sex").ToString()) %>'>
</asp:Label>
</ItemTemplate>
<%@ Import Namespace="System" %>
<html>
<head>
<title> New ASP.NET Document </title>
</head>
<body bgcolor="#FFFFFF" topmargin="0" marginheight="0">
<script language="C#" runat="server"> void Page_Load(Object Source, EventArgs E) {
//你自己的数据绑定代码
}
void DataGrid1_ItemCreated(Object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
//IsColor假设为数据库中的那个颜色字段
String IsColor = ((DbDataRecord)e.Item.DataItem)["IsColor"].ToString(); if(IsColor.Length > 0)
{
e.Item.ForeColor = "#990000";
}
}
}
</script>
<form runat="server" method="">
<asp:DataGrid OnItemCreated="DataGrid1_ItemCreated" runat="server" id="DataGrid1">
</asp:DataGrid>
</form>
</body>
</html>