asp.net双层repeater嵌套

发布时间:2018-10-24 09:37:11编辑:佚名阅读(637)

前台代码:

<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate>
            <p>第一层</p>
            <%#Eval("id")%>
             <asp:Repeater ID="Repeater2" runat="server">
                    <ItemTemplate>
                        <p>第二层</p>
                        <%#Eval("id")%>
                    </ItemTemplate>
              </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

后台代码:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Repeater rep = e.Item.FindControl("Repeater2") as Repeater;
        DataRowView rowv = (DataRowView)e.Item.DataItem;
        int Id = Convert.ToInt32(rowv["id"]);
        //根据条件查找数据,此处省略
        if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
        {
            rep.DataSource = ds.Tables[0];
            rep.DataBind();
        }
    }
}


  关键字:asp.net双层repeater嵌套


鼓掌

0

正能量

0

0

呵呵

0


评论区