<asp:ListView ID="lvClass" runat="server" DataSourceID="LinqDataSource1" OnItemDataBound ="lvResult_ItemDataBound" >
<LayoutTemplate>
You teach these classes:
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" ></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<asp:Label ID="lblClass" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Class") + ", " %>' ></asp:Label>
</ItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="MyDataContext" TableName="ClassList"
onselected="LinqDataSource1_Selected">
</asp:LinqDataSource>
Code Behind:
//remove the last comma(,)
public class Test : System.Web.UI.Page
{
int iCount = 0;
protected void lvResult_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label lblClass = e.Item.FindControl("lblClass") as Label;
ListViewDataItem lvItem = e.Item as ListViewDataItem ;
if (lblClass != null)
if (lvItem.DataItemIndex == (iCount - 1))
lblClass.Text = lblClass.Text.Substring(0, lblClass.Text.ToString().Length - 2);
}
}
protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)
{
iCount = e.TotalRowCount;
}
}