xorpower
xorpower

Reputation: 18963

Give Hex color code as a gridview background color

How can I give an hex color code to gridview's row background color? I know that it is to be given on a rowdatabound event. But I am not sure whether a hex color code can be given or a default - System.Drawing.Color.(ColorName) would only work?

Upvotes: 3

Views: 16533

Answers (2)

Mrchief
Mrchief

Reputation: 76208

You need to assign a System.Drawing.Color type. But you can easily get the instance from hex or named values like shown below:

Color clr = ColorTranslator.FromHtml("#FFFF33");

named colors:

Color clr =  ColorTranslator.FromHtml("Red");

Also, you can directly specify the background/foreground color in the markup for gridview:

 <asp:GridView ID="gridView1" Runat="server" 
    ...
    <RowStyle ForeColor="red" BackColor="#FFF7E7"></RowStyle>
 </asp:GridView>

You can use both named and hex values.

Upvotes: 8

Related Questions