zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }

  • 相关阅读:
    MySQL常用命令记录
    VM新安装centos7无法连接网络的问题
    nginx + tomcat实现负载均衡
    Redis集群分布(Windows版)
    7.2 基础知识ArrayMap
    7.1 基础知识Android消息处理机制
    6.5 Android硬件访问服务使用反射
    6.4 Android硬件访问服务编写HAL代码
    6.3 Android硬件访问服务APP代码
    6.2、Android硬件访问服务编写系统代码
  • 原文地址:https://www.cnblogs.com/shanlin/p/2124977.html
Copyright © 2011-2022 走看看