首页 > 开发 > 综合 > 正文

关于多层repeater,datagrid,datalist嵌套的示例

2024-07-21 02:15:51
字体:
来源:转载
供稿:网友
菜鸟学堂:

常常在csdn上看到有网友问如何才能实现repeater,datalist, datagrid的嵌套问题,下面给出一个3层嵌套的示例,可以无限级嵌套下去

<asp:repeater id="rpt_catalog" onitemdatabound="rpt_catalog_onitemdatabound" runat="server">
<itemtemplate>最顶层repeater,index:<%#container.dataitem%><br>
<asp:repeater id="rpt_board" onitemdatabound="rpt_board_onitemdatabound" runat="server">
<itemtemplate>&nbsp;&nbsp;&nbsp;&nbsp;第2层repeater,index:<%#container.dataitem%><br>
<asp:repeater id="rpt_boardmaster" runat="server">
<itemtemplate>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;第3层repeater,index:<%#container.dataitem%><br>
</itemtemplate>
</asp:repeater>
</itemtemplate>
</asp:repeater>
</itemtemplate>
</asp:repeater>



    private intfirst as integer
    private intsecond as integer

    private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
        'put user code to initialize the page here
        dim al as new arraylist
        al.add(0)
        al.add(1)
        rpt_catalog.datasource = al
        rpt_catalog.databind()
    end sub

    sub rpt_catalog_onitemdatabound(byval sender as object, byval e as repeateritemeventargs)
        dim rpt as repeater
        rpt = e.item.findcontrol("rpt_board")
        intfirst = e.item.itemindex

        dim al as new arraylist
        al.add(intfirst & ".0")
        al.add(intfirst & ".1")
        rpt.datasource = al
        rpt.databind()
    end sub

    sub rpt_board_onitemdatabound(byval sender as object, byval e as repeateritemeventargs)
         dim rpt as repeater
        rpt = e.item.findcontrol("rpt_boardmaster")
        intsecond = e.item.itemindex
        dim al as new arraylist
        al.add(intfirst & "." & intsecond & ".0")
        al.add(intfirst & "." & intsecond & ".1")
        rpt.datasource = al
        rpt.databind()
    end sub



代码经过测试,但请自行优化
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表