repeater,datalist, datagrid的嵌套问题

本文介绍了一个ASP.NET中Repeater控件三层嵌套使用的实例,展示了如何通过设置不同层级的数据源来实现无限级嵌套。此方法适用于需要展示多层次数据的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

<asp:repeater id="rpt_catalog" onitemdatabound="rpt_catalog_onitemdatabound" runat="server"> 
<itemtemplate>最顶层repeater,index:<%#container.dataitem%>
 
<asp:repeater id="rpt_board" onitemdatabound="rpt_board_onitemdatabound" runat="server"> 
<itemtemplate> 第2层repeater,index:<%#container.dataitem%>
 
<asp:repeater id="rpt_boardmaster" runat="server"> 
<itemtemplate> 第3层repeater,index:<%#container.dataitem%>
 
</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


代码经过测试,但请自行优化 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值