[英]Difficulty in displaying data using repeater
I am trying to display shopping categories with its sub categories and sub-sub categories using repeater.. Data is binding but it is not being displayed.. Can anyone help why? 我试图使用转发器显示其子类别和子子类别的购物类别。数据是绑定但它没有显示..任何人都可以帮助为什么? here's my code: 这是我的代码:
.aspx file .aspx文件
<asp:Repeater ID="CategoryRepeater" runat="server" OnItemDataBound="CategoryRepeater_OnItemDataBound">
<ItemTemplate>
<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>'<%#Eval("CategoryName") %>></a><br />
<asp:Repeater ID="SubCategoryRepeater" runat="server" OnItemDataBound="SubCategoryRepeater_OnItemDataBound">
<ItemTemplate>
<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>'<%#Eval("SubCategoryName") %>></a><br />
<asp:Repeater ID="SubSubCategoryRepeater" runat="server">
<ItemTemplate>
<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>&SubSubCategoryId=<%#Eval("SubSubCategoryId") %>'<%#Eval("SubSubCategoryName") %>></a><br />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
C# Code: C#代码:
protected void CategoryRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView dataItem = e.Item.DataItem as DataRowView;
int categoryId = Convert.ToInt32(dataItem["CategoryId"]);
Repeater rp = (Repeater)e.Item.FindControl("SubCategoryRepeater");
ds = us.SelectSubCategories(categoryId);
rp.DataSource = ds;
rp.DataBind();
}
}
protected void SubCategoryRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView dataItem = e.Item.DataItem as DataRowView;
int SubCategoryId = Convert.ToInt32(dataItem["SubCategoryId"]);
Repeater rp1 = (Repeater)e.Item.FindControl("SubSubCategoryRepeater");
ds1 = us.SelectSubSubCategories(SubCategoryId);
rp1.DataSource = ds1;
rp1.DataBind();
}
}
Check your source code to make sure nothing is being output to the page. 检查源代码以确保没有任何内容输出到页面。 I think you just have the category name being rendered inside the anchor tag. 我想你只是在锚标签内呈现了类别名称。
Here is the same code with the evals simplified to see what is going on 这是相同的代码,简化了evals以查看发生了什么
<a href='Clothing.aspx?CategoryId={catid}'{name}></a>
Should be: 应该:
<a href='Clothing.aspx?CategoryId={catid}'>{name}</a>
or 要么
<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>'><%#Eval("CategoryName") %></a>
Same mistake was done in all three locations. 在所有三个地点都犯了同样的错误。
I think everything is correct from the code, but your output is wrong. 我认为代码中的一切都是正确的,但你的输出是错误的。
You are doing this: 你这样做:
<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>'<%#Eval("SubCategoryName") %>></a><br />
But it needs to be 但它需要
<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>'><%#Eval("SubCategoryName") %></a><br />
Noticed I moved the '>' back behind <%# Eval("SubCategoryName")%> 注意到我将'>'移回<%#Eval(“SubCategoryName”)%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.