Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用嵌套转发器添加多个(嵌套)类别?_C#_Asp.net_Nested_Repeater_Categories - Fatal编程技术网

C# 如何使用嵌套转发器添加多个(嵌套)类别?

C# 如何使用嵌套转发器添加多个(嵌套)类别?,c#,asp.net,nested,repeater,categories,C#,Asp.net,Nested,Repeater,Categories,我想使用嵌套中继器添加多个类别->子类别->子类别: 与此类似,但从数据库中有更多的类别和子类别 <form id="form1" runat="server"> <div> <ul> <asp:Repeater ID="outerRep" runat="server" OnItemDataBound="outerRep_ItemDataBound"> <Ite

我想使用嵌套中继器添加多个
类别->子类别->子类别

与此类似,但从数据库中有更多的类别和子类别

<form id="form1" runat="server">
    <div>
        <ul>
            <asp:Repeater ID="outerRep" runat="server" OnItemDataBound="outerRep_ItemDataBound">
                <ItemTemplate>
                    <li>
                        <asp:Label Font-Size="Large" Font-Bold="true" ID="lblCategoryName" runat="server" Text='<%# Eval("CategoryName") %>' />
                    </li>
                    <ul>
                        <asp:Repeater ID="innerRep" runat="server">
                            <ItemTemplate>
                                <li style="background-color: AliceBlue">
                                    <asp:HyperLink ID="hlProductName" runat="server" Text='<%# Eval("SubCategoryName")%>' />
                                </li>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ul>
                </ItemTemplate>
            </asp:Repeater>
        </ul>
    </div>
</form>
或者有更好的方法吗?请帮忙

protected void Page_Load(object sender, EventArgs e)
{
    BindData();
}

private void BindData()
{
    SqlConnection myConnection = new SqlConnection("Data Source=.; uid=sa; pwd=xxx;database=registration;");
    SqlCommand myCommand = new SqlCommand("usp_GetProductsForCategories", myConnection);

    myCommand.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter ad = new SqlDataAdapter(myCommand);
    DataSet ds = new DataSet();

    ad.Fill(ds);

    // Attach the relationship to the dataSet
    ds.Relations.Add(new DataRelation(
        "CategoriesRelation",
        ds.Tables[0].Columns["CategoryID"],
        ds.Tables[1].Columns["CategoryID"]));

    outerRep.DataSource = ds.Tables[0];
    outerRep.DataBind();
}

protected void outerRep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item ||
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
        DataRowView drv = e.Item.DataItem as DataRowView;
        Repeater innerRep = e.Item.FindControl("innerRep") as Repeater;

        innerRep.DataSource = drv.CreateChildView("CategoriesRelation");
        innerRep.DataBind();
    }
}