[英]DataList grouping items by category
I have a datalist and I would like to group my items in 3 columns with one item header(category) like: 我有一个数据列表,我想用一个项目标题(类别)将我的项目分为3列:
[Category A] [类别A]
[ItemA] [ItemB] [ItemC] [ItemA] [ItemB] [ItemC]
[Category B] [类别B]
[ItemA] [ItemB] [ItemC] [ItemA] [ItemB] [ItemC]
My query retrieves the items in this structure: 我的查询检索以下结构中的项目:
1 CategoryA ItemA 2 CategoryA ItemB 3 CategoryA ItemC 4 CategoryB ItemA 5 CategoryB ItemB 6 CategoryB ItemC 1类别A项A 2类别A项B 3类别A项C 4类别B项A 5类别B项B 6类别B项C
This is what I have, but does not work as expected. 这是我所拥有的,但不能按预期工作。 Any ideas?
有任何想法吗?
<ItemTemplate>
SubCatName:
<asp:Label ID="SubCatNameLabel" runat="server" Text='<%# Eval("SubCatName") %>' /><br />
<ItemTemplate>
Name:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Name")%>' />
<div id="Div1" style="clear: both" runat="server" Visible="<%# (Container.ItemIndex + 1) Mod 3 = 0%>"></div>
</ItemTemplate>
</ItemTemplate>
String previousName = "";
protected void MyDataList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label Label1 = (Label)e.Item.FindControl("Label1");
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
string currentName = rowView["Name"].ToString();
if (currentName == previousName)
{
Label1.Text = "";
}
else
{
Label1.Text = currentName;
}
previousName = currentName;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.