Home > Forum > ASP.NET > Set alternate color in Asp.net Listvew control

Set alternate color in Asp.net Listvew control

by Thamil   on Feb 20, 2013   Category: ASP.NET  |  Views: 3674    |  Points: 5   |  Gold 
  Reply

How to set alternate color in each row using asp.net listview control.

Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :Set alternate color in Asp.net Listvew control   
by Thamil
on Feb 20 2013 2:25AM
Points : 10
Gold 
Please see the below code, by using AlternatingItemTemplate property we can able to set the alternate color in each row.

<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" DataSourceID="SqlDataSource1"
OnItemCommand="ListView1_ItemCommand" OnSorting="ListView1_Sorting" >
<AlternatingItemTemplate>
<tr style="background-color: #FFFAAA;">
<td>
<asp:Label ID="LabelID" runat="server" Text='<%# Eval("Id") %>' />
</td>
<td>
<asp:Label ID="LabelName" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
</AlternatingItemTemplate>

<ItemTemplate>
<tr style="background-color: #FVCCSF;">
<td>
<asp:Label ID="LabelID" runat="server" Text='<%# Eval("Id") %>' />
</td>
<td>
<asp:Label ID="LabelName" runat="server" Text='<%# Eval("Name") %>' />
</td>
</tr>
</ItemTemplate>
</asp:ListView>

Recent Post

Latest Posts