开发者

Give Hex color code as a gridview background color

开发者 https://www.devze.com 2023-03-26 02:45 出处:网络
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 - Syst

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?


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.


Look here for conversions between int, string and hex values

0

精彩评论

暂无评论...
验证码 换一张
取 消