Repeater嵌套

<asp:Repeater ID="Repeater1" runat="server"   
 
    onitemdatabound="Repeater1_ItemDataBound">  
 
<ItemTemplate>  
 
<tr><td>  
 
    <span style="width:168px;" class="Prent"><%#Eval("name")%></span>  
 
    </td></tr>  <tr class="Hover" ><td class="Hover" >  
 
    <asp:Repeater ID="Repeater2" runat="server" OnItemCommand="Repeater2_ItemCommand" onitemdatabound="Repeater2_ItemDataBound">  
 
    <ItemTemplate>         
 
        <span class="Hover"  style="vertical-align:bottom; line-height:20px;"><asp:ImageButton ID="ImageButton1" runat="server" />  <a target="_blank" href="/bbs/showforum.aspx?forumid=<%# Eval("fid")%>">2<%#Eval("name")%></a></span>  
 
    <br />  
 
    <asp:Repeater ID="Repeater3" runat="server">  
 
    <ItemTemplate>  
 
    <span class="Hover"  style="vertical-align:bottom; line-height:20px;"><a target="_blank" href="/bbs/showforum.aspx?forumid=<%# Eval("fid")%>">3<%#Eval("name")%><img id="Img1" style="border:0px;" alt="" runat="server" src="/TreeLineImages/smallpic.gif" /></a></span>  
 
    <br />  
 
    </ItemTemplate>  
 
    </asp:Repeater>  
 
      
 
    </ItemTemplate>  
 
    </asp:Repeater>  
 
    </td>  
 
</tr>  
 
</ItemTemplate>  
 
</asp:Repeater> 

<asp:Repeater ID="Repeater1" runat="server"

    onitemdatabound="Repeater1_ItemDataBound">

<ItemTemplate>

<tr><td>

    <span style="width:168px;" class="Prent"><%#Eval("name")%></span>

    </td></tr>  <tr class="Hover" ><td class="Hover" >

    <asp:Repeater ID="Repeater2" runat="server" OnItemCommand="Repeater2_ItemCommand" onitemdatabound="Repeater2_ItemDataBound">

    <ItemTemplate>      

        <span class="Hover"  style="vertical-align:bottom; line-height:20px;"><asp:ImageButton ID="ImageButton1" runat="server" />  <a target="_blank" href="/bbs/showforum.aspx?forumid=<%# Eval("fid")%>">2<%#Eval("name")%></a></span>

    <br />

    <asp:Repeater ID="Repeater3" runat="server">

    <ItemTemplate>

    <span class="Hover"  style="vertical-align:bottom; line-height:20px;"><a target="_blank" href="/bbs/showforum.aspx?forumid=<%# Eval("fid")%>">3<%#Eval("name")%><img id="Img1" style="border:0px;" alt="" runat="server" src="/TreeLineImages/smallpic.gif" /></a></span>

    <br />

    </ItemTemplate>

    </asp:Repeater>

   

    </ItemTemplate>

    </asp:Repeater>

    </td>

</tr>

</ItemTemplate>

</asp:Repeater>cs:

view plaincopy to clipboardprint?
protected void Page_Load(object sender, EventArgs e)  
 
   {  
 
 
 
       string sql;  
 
       if (!Page.IsPostBack)  
 
       {  
 
             
 
           sql="select * from dnt_forums where layer=0";  
 
           access_data.bind_data(sql, this.Repeater1);  
 
   
 
       }  
 
         
 
   }  
 
   protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)  
 
   {  
 
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  
 
       {  
 
           Repeater subRep = (Repeater)e.Item.FindControl("Repeater2");  
 
           DataRowView dr = (DataRowView)e.Item.DataItem;  
 
           int Perentid = Convert.ToInt32(dr["fid"]);  
 
           data.bind_data("select *from dnt_forums where parentid=" + Perentid, subRep);  
 
             
 
       }  
 
   }  
 
    
 
   protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)  
 
   {  
 
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)  
 
       {  
 
           Repeater subRepA = (Repeater)e.Item.FindControl("Repeater3");  
 
           ImageButton Img = (ImageButton)e.Item.FindControl("ImageButton1");  
 
           DataRowView drA = (DataRowView)e.Item.DataItem;   
 
           int Perentid = Convert.ToInt32(drA["fid"]);  
 
           data.bind_data("select *from dnt_forums where parentid=" + Perentid, subRepA);  
 
           if (subRepA.Items.Count==0)  
 
           {  
 
               Img.ImageUrl = "~/TreeLineImages/lminus.gif";  
 
           }  
 
           else 
 
           {  
 
               Img.ImageUrl = "~/TreeLineImages/plus.gif";  
 
               subRepA.Visible = false;   
 
           }  
 
                       
 
       }          
 
         
 
   }  
 
   protected void Repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)  
 
   {  
 
       Repeater subRepA = (Repeater)e.Item.FindControl("Repeater3");  
 
       ImageButton Img = (ImageButton)e.Item.FindControl("ImageButton1");          
 
            
 
        
 
       if (subRepA.Visible)  
 
       {  
 
           Img.ImageUrl = "~/TreeLineImages/plus.gif";  
 
           subRepA.Visible = false;  
 
       }  
 
       else 
 
       {  
 
           Img.ImageUrl = "~/TreeLineImages/minus.gif";  
 
           subRepA.Visible = true;  
 
       }  
 
        
 
   } 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/XJY123/archive/2008/07/04/2612207.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值