Reputation: 2176
I have a gridview
and on RowDataBound
I use this code to change the background of every second row so the gridview
can be read better:
if (e.Row.RowIndex % 2 != 0)
{
e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#f2f2f2");
}
After that I use a dropdown
to show only relevant rows of my gridview
and hide (visible = false)
the rows I didn't want to display. The rownumber doesn't change so the different background doesn't match for every second row now.
Now I'm looking to get the rownumbers of only the visible rows to change the color of every second row. Thanks
Upvotes: 2
Views: 2234
Reputation: 73791
You can use the CSS technique mentioned in Alternate table row color using CSS?:
.alternatingRows > tbody > tr:nth-child(even)
{
background-color: #f2f2f2;
}
The style class is applied to the GridView itself:
<asp:GridView ID="GridView1" runat="server" CssClass="alternatingRows" ... >
Upvotes: 1
Reputation: 407
Try AlternatingRowStyle property of the gridView.
A documentation on msdn to get you started.
Upvotes: 4