I'm looking for a way to change the font colour on alternate rows within a datagrid. e.g. normal row would be green and the alternate row would be blue.
I can change either by using
- me.datagrid.Styles.Row.Forcolour
- me.datagrid.Styles.AlternatingRow.Forcolour
The problem is that I am having trouble using both of them together as I need to开发者_如何学编程 manipulate both colours. I have created a HtmlRowPrepared event and have been setting them there, however, If I set the Row.Forcolour first, it will over ride the AlternatingRow.Forcolour and vice versa.
This needs to be done via SEVER SIDE code only as the colour choices are held in the database.
If you could help I would be very grateful.
Many thanks
A GridView has style attributes which you can declare in the HTML.
<asp:GridView id="GridView1" runat="server">
<AlternatingRowStyle BackColor="Black" ForeColor="White" CssClass="alternating-row" />
<RowStyle BackColor="White" ForeColor="Black" CssClass="row" />
</asp:GridView>
In these tags you can declare all you need, also adding a CssClass to each. I would suggest using the CssClass only, and then updating the styles in your stylesheet. This is better for updating styles in the future.
Please paste some code so that we can understand how you are doing this well you can set these values aspx page where you define your control
<ItemStyle ForeColor="Green"/>
<AlternatingItemStyle ForeColor="Blue" />
I m sure this will work and if it doesnt please paste your code for better understanding
精彩评论