Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 239203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:33:59+00:00 2026-05-11T20:33:59+00:00

The ASP.NET ListView control like most databound ASP.NET controls has an AlternatingItemTemplate which you

  • 0

The ASP.NET ListView control like most databound ASP.NET controls has an AlternatingItemTemplate which you can use for example to render different css class for odd and even rows. The control also has GroupTemplate which you can use to group items and display for example 3 items in TDs that are grouped in a TR. However there is no alternating group template. My question is how to alternate the class attribute of a tr in a GroupTemplate. Basically I want to have 3 items in a TR and alternating styles on odd and even TRs.

I want to avoid nesting one databound control in another and I’ve already tried binding the class of the TR in a databinding expression <%# Alternate() %> but it seems that databinding expressions are only called in the itemtemplate (obviously they are used in the databind event and it is not called for the group template)

Any ideas?

Example code:

    <asp:ListView ID="lv1" runat="server" EnableViewState="false" GroupItemCount="3">
    <LayoutTemplate>
        <table class="asd">
            <asp:PlaceHolder ID="groupPlaceholder" runat="server"></asp:PlaceHolder>
        </table>
    </LayoutTemplate>
    <GroupTemplate>
        <tr class='<%# GetAlternatingCssClass() %>'>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
        </tr>
    </GroupTemplate>
    <ItemTemplate>
        <td>
            <asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>'> <%# Eval("Text") %> </asp:HyperLink>
        </td>
    </ItemTemplate>
</asp:ListView>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:34:00+00:00Added an answer on May 11, 2026 at 8:34 pm

    Firstly:

    <GroupTemplate>
        <tr class='<%# GetAlternatingCssClass() %>'>
            <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
        </tr>
    </GroupTemplate>
    

    will only get evaluated once for the ListView as it’s evaluated at the point the page is processed, not for every time the element is accessed. To implement this as intended here I think you’d need to be overriding the Render method for the ListView to alternate the class based on the GroupItemCount. I’ve not coded this so this is supposition.

    The GroupTemplate is intended to deliver a kind of flow layout where each item is a self contained element, i.e. a complete product listing, and where the items and rows are not connected (as the would be as cells in a row representing fields in a record). As such alternating the row colour does nothing to help data representation but is purely asthetic (and possibly confusing for users used to seeing different records identified in this way, it may cause them to make inferences about the data relationships that don’t actually exist).

    I think you are going to have to do a lot of work to get what you want from the basic ListView, I think the first question to ask yourself is why you want this and is it a user requirement or your requirement based on asthetics (nothing wrong with that per se but you appreciate that the controls are designed for function rather than asthetic). If it isn’t a user requirement, do they want to pay for the effort to resolve this?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to do a weird thing with the asp.net listview control. I
Using ASP.NET 3.5 ListView control. I would like to capture the value of my
I'm dynamically loading images from a different website into an asp.net ListView control like
I have a ListView control in Asp.Net WebForms which display a set of elements,
I'm using the new ASP.Net ListView control to list database items that will be
I am trying to get an ASP.NET 3.5 ListView control to select and highlight
I'm using the ListView control (ASP.NET 2008) to show a bunch of lines of
ASP.NET: Could anyone provide some C# paging codes in Repeater or ListView controls for
I am using an ASP.NET ListView control and, at the moment, I have a
How do get the paging functionality (like we have in asp.net gridview) in Listview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.