欢迎光临
我们一直在努力

关于多层repeater,datagrid,datalist嵌套的示例-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

常常在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

代码经过测试,但请自行优化

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 关于多层repeater,datagrid,datalist嵌套的示例-.NET教程,Asp.Net开发
分享到: 更多 (0)