is there any easy way to style the last item in a ListView control? Basicly need to append a class.
Cheers
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With