示例圖片:
前臺綁定數據我用的數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)
即可顯示自己設置的字體顏色。