Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling last item in a ListView

is there any easy way to style the last item in a ListView control? Basicly need to append a class.

Cheers

like image 668
flalar Avatar asked Dec 22 '22 08:12

flalar


1 Answers

Comma separate a list of customers names. The last customer name will end with a dot.

Customer A, Customer B, Customer C.

<asp:ListView ID="lvCustomers" runat="server">
  <LayoutTemplate>
    <div id="itemPlaceHolder" runat="server"></div>
  </LayoutTemplate>
  <ItemTemplate>
    <%# Eval("CustomerName")<%# Container.DisplayIndex == (Container.BindingContainer.As<ListView>().DataSource.As<System.Collections.Generic.List<String>>().Count - 1) ? "." : ", " %>
  </ItemTemplate>
</asp:ListView>

This uses an extension method 'As':

/// <summary>
/// Returns this object casted as a different type.
/// </summary>
/// <typeparam name="T">A type</typeparam>
/// <param name="obj">An object</param>
/// <returns>A boolean value.</returns>
public static T As<T>(this object obj) where T : class
{
    if (obj == null) return null;

    return obj as T;
}
like image 57
mathijsuitmegen Avatar answered Jan 18 '23 17:01

mathijsuitmegen