• Repeater控件嵌套使用


    前台页面代码:

    <ul>
                <asp:Repeater ID="rptClass1" runat="server" OnItemDataBound=" rptClass1_ItemDataBound">
                    <ItemTemplate>
                        <li><a href="ProtectList.aspx?ClassID=<%#Eval("ID") %>">
                            <%#Eval("ClassName") %></a>
                            <ul>
                                <asp:Repeater ID="rptClass2" runat="server">
                                    <ItemTemplate>
                                        <li><a href="ProtectList.aspx?ClassID=<%#Eval("ID") %>">
                                            <%#Eval("ClassName") %></a></li>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </ul>
                        </li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>

    后台页面代码 :

    public void GetClass()//加载产品一级分类
            {
                DataTable dt = bllClass.GetDataTable(0, "", "ParentID=13 and IsView=1", "Oid");
                this.rptClass1.DataSource = dt.DefaultView;
                this.rptClass1.DataBind();

                dt.Dispose();
            }

            protected void rptClass1_ItemDataBound(object sender, RepeaterItemEventArgs e)//添加二级分类
            {
                //  判断里层的repeater处于哪个外层repeater的哪个位置
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    Repeater rptClass = e.Item.FindControl("rptClass") as Repeater; //    查找内层Repeater并转换到相应类型
                    DataRowView drv = (DataRowView)e.Item.DataItem;   //   找到外层Repeater关联的数据项

                    long id = long.Parse(drv["ID"].ToString()); //  取得pID
                    TianDao.BLL.BusinessTD_Base_Class bllClass2 = new TianDao.BLL.BusinessTD_Base_Class();
                    DataTable dt = bllClass2.GetDataTable(0, "", "ParentID=" + id + " and IsView=1", "Oid");

                    rptClass.DataSource = dt.DefaultView;
                    rptClass.DataBind();
                    dt.Dispose();
                }
            }
        }

  • 相关阅读:
    系统分析师考试
    系统分析师
    软件设计师考试
    海恩法则”的启示:制度不落到实处事故必发
    eclipse下生成Java类图和时序图,生成UML图
    bzoj4010【HNOI2015】菜肴制作
    atitit.提升开发效率---MDA 软件开发方式的革命(5)----列表查询建模
    【数据结构和算法16】堆排序
    这一路走来,冷暖自知 (附算法demos)
    c++实现二叉搜索树
  • 原文地址:https://www.cnblogs.com/shanlin/p/2124977.html
Copyright © 2020-2023  润新知