Reputation: 131
i'm looking to get a BackColor of Label in ASP.NET Form and Change this label's Color with this value is that possible ?
<asp:Label ID="Label2" runat="server" Text="Label" BackColor='<%# System.Drawing.Color.FromName(Eval(Container.DataItem,"BgColor").ToString())%>'></asp:Label>
thanks.
Upvotes: 1
Views: 11774
Reputation: 21
you should used ColorHex like : #602A4D And not used .Tostring() to this code :
BackColor='<%# System.Drawing.Color.FromName(Eval("BgColor"))%>'>
Upvotes: 0
Reputation: 71
//Label, setting forecolor by HexaColor
lblResult.ForeColor = System.Drawing.ColorTranslator.FromHtml("#E93301");
or
//Label, setting forecolor by color Name
lblResult.ForeColor = System.Drawing.Color.Red;
Upvotes: 7
Reputation: 3460
You should be using FromHtml:
<%# System.Drawing.ColorTranslator.FromHtml(Eval("BgColor")%>
Upvotes: 4
Reputation: 26
the format is 3300FF in database
'<%# System.Drawing.Color.FromName(Eval("BgColor").ToString())%>'
but tha label display none color
Upvotes: 0
Reputation: 94645
You may try,
<asp:Label
ID="Label2"
runat="server"
Text="Label"
BackColor='<%# System.Drawing.Color.FromName(Eval("BgColor").ToString())%>'>
</asp:Label>
Upvotes: 1