我有一个数据列表,我想将我的项目分为3列,其中包含一个项目标题(类别):
[A类]
[ItemA] [ItemB] [ItemC]
[B类]
[ItemA] [ItemB] [ItemC]
我的查询检索此结构中的项目:
1 CategoryA ItemA 2类别A项目B. 3类别A项目C. 4类别B项目A. 5类别B项目B. 6 B类ItemC
这就是我所拥有的,但不能按预期工作。有什么想法吗?
<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>
答案 0 :(得分:0)
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;
}
}