Wednesday, August 15, 2012

Dynamically set Label BackColor (Control Back Color) in ASP.NET Grid

I engaged with fining a method of dynamically change control’s background color in a ASP.NET grid based on data in the data source.

I used the following code for get the task done.

<asp:TemplateField HeaderText="Color 01">
<
ItemTemplate>
<
asp:Label ID="lblColor1" runat="server"
BackColor='<%# System.Drawing.ColorTranslator.FromHtml((String)Eval("Color1")) %>' Text='<%# Bind("Color1") %>' >
       </asp:Label>
</
ItemTemplate>
</
asp:TemplateField>
Post a Comment