示例图片:
前台绑定数据我用的数Repearer
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testss.aspx.cs" Inherits="testss" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptTest" runat="server">
<ItemTemplate>
<tr>
<td width="50" height="30" style='<%#GetColor(Eval("TSET")) %>'>
<%#Eval("TSET")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="无记录.." runat="server" Visible='<%#bool.Parse((rptTest.Items.Count==0).ToString())%>'></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
后台代码:
#region 文字背景色(Start)
public static string GetColor(object obj)
{
if (obj == DBNull.Value)
{
return string.Empty;
}
return GetColor(obj.ToString());
}
public static string GetColor(string val)
{
if (val == "测试1")
{
return "color:#FF0000";//红色
}
else if (val == "测试2")
{
return "color:#0000EE";//红色
}
else
{
return "color:#000000";//黑色
}
}
#endregion 文字背景色(End)
即可显示自己设置的字体颜色。