在Repeater 中使用Repeater的方法, Repeater2 内嵌 Repeater1操作

在Repeater 中使用Repeater的方法

前台代码:

<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
        <ItemTemplate>
            <div class="nav_title">
                <%#Eval("class") %></div>
            <ul class="nav">
                <asp:Repeater ID="Repeater2" runat="server">
                    <ItemTemplate>
                        <li><a class="<%#Convert.ToInt32(Eval("id"))==sortId?"select":"" %>" href="line.aspx?sort_id=<%#Eval("id") %>"><%#Eval("sort") %></a></li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
        </ItemTemplate>
    </asp:Repeater>

后台代码(Repeater就不写了,直接第二个):

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            Repeater rptProduct = (Repeater)e.Item.FindControl("Repeater2");
            //找到分类Repeater关联的数据项 
            DataRowView rowv = (DataRowView)e.Item.DataItem;
            //提取分类ID 
            string classKey = rowv["class"].ToString();
            //根据分类ID查询该分类下的产品,并绑定产品Repeater 
            DataSet st = AccessHelper.ExecuteDataSet("select distinct [sort],[id] from [line_sort] where [class]=@class",AccessHelper.Parameter("@class",classKey));
            rptProduct.DataSource = st.Tables[0];
            rptProduct.DataBind();
        }
    }

posted @ 2011-06-13 22:27  hen  阅读(1172)  评论(0编辑  收藏  举报