我有一個Gridview包含許多TemplateField。
我想使我的HTML源每<td>
等於顏色保存在我的數據庫
我嘗試代碼下方,但不工作這是給我的內心<td>
我的顏色,但一個<span>
標籤,但不會出現在瀏覽器如何使用Eval在TemplateField中更改顏色
<asp:TemplateField HeaderText="BackGround Color">
<ItemTemplate>
<asp:Label ID="lblBackColor" runat="server"
BackColor='<%# ConvertFromHexToColor(Eval("BackColor").ToString()) %>'>
</asp:Label>
<itemstyle width="20%" horizontalalign="Center" />
</ItemTemplate>
</asp:TemplateField>
C#代碼工作
public Color ConvertFromHexToColor(string hex)
{
string colorcode = hex;
int argb = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
Color clr = Color.FromArgb(argb);
return clr;
}
這是源HTML和CSS代碼在瀏覽器中
<td>
<span id="BodyZone__ThemesGrid_lblForeColor_0" style="background-color: #FFFFFF;"></span>
<itemstyle width="20%" horizontalalign="Center">
</itemstyle>
</td>
CSS
table.activity_datatable td {
padding: 8px 15px;
color: #6c6c6c;
vertical-align: middle;
-webkit-transition: all 0.2s;
}
沒有文本跨度,所以沒有顏色在backgroupnd – 2013-02-11 07:11:20
你是什麼意思**每個td ** – 2013-02-11 07:17:47