user2380844
user2380844

Reputation: 307

Alternate row color in gridview

i am using a gird view and fetching from datatase and populating the gridview for applying alternate color in row i am using AlternatingRowStyle

<asp:GridView ID="gvDetails" runat="server" > 
<AlternatingRowStyle BackColor="#dcecf4"   />
</asp:GridView>

the above code gives alternate color in 2,4,6 etc., rows,but my requirement is the rows alternate color should start from 1,3,5 etc., rows

Upvotes: 1

Views: 10607

Answers (1)

Joshua Frank
Joshua Frank

Reputation: 13838

You want RowStyle instead of AlternatingRowStyle:

<asp:GridView ... >
  <RowStyle CssClass="oddRow" />
  <AlternatingRowStyle CssClass="evenRow" />
</asp:GridView ... >

Here I'm using styles, but you could specify something like BackColor directly. As the style names indicate, RowStyle applies to the odd rows (1, 3, 5, ...) and AlternatingRowStyle applies to the even rows (2, 4, 6, ...).

Upvotes: 3

Related Questions