码迷,mamicode.com
首页 > 其他好文 > 详细

repeater三级嵌套绑定

时间:2015-06-03 11:25:43      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

从别的网站转过来的,以备自己后用,感谢原创作者!

 

前台aspx

<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound">
        <HeaderTemplate> <table width=400 cellpadding=0 cellspacing=0></HeaderTemplate>
           <ItemTemplate><tr>
        <td><font color=black style="font-size: medium; color: #000000"><b><%# DataBinder.Eval(Container.DataItem,"CategoryName")%></b></font></td></tr>
                 <tr><td align=right>
                        <asp:Repeater ID="rpt2" runat="server">
                            <HeaderTemplate>
                               <table width=360 align=center cellpadding=0 cellspacing=0>
                            </HeaderTemplate>
                                 <ItemTemplate>
                                      <tr>
                                        <td align=left width=200 style="color: #000080; text-decoration: none; font-family: Calibri;"><font color=black>+</font><%# DataBinder.Eval(Container.DataItem,"CategoryName")%></td>
                                        <td width=80 align=center>
                                            <a href=ProductSort.aspx?type=1&id=<%# DataBinder.Eval(Container.DataItem,"ID")%>>修改</a></td>
                                          
                                        <td width=80 align=center>
                                          <a href=ProductSort.aspx?type=2&id=<%# DataBinder.Eval(Container.DataItem,"ID")%>>删除</a> 
                                        </td>
                                      </tr>
                                      <tr>
                                         <td align=right colspan=3>
                                              <asp:Repeater ID="rpt3" runat="server">
                                                 <HeaderTemplate>
                                                    <table width=320 align=center cellpadding=0 cellspacing=0>
                                                 </HeaderTemplate>
                                                    <ItemTemplate>
                                                       <tr>
                                                          <td align=left width=160 style="color: #000080; text-decoration: none; font-family: Calibri;"><font color=black>-</font><%# DataBinder.Eval(Container.DataItem,"CategoryName")%></td>
                                                          <td width=80 align=center>
                                                              <a href=ProductSort.aspx?type=1&id=<%# DataBinder.Eval(Container.DataItem,"ID")%>>修改</a>
                                                          </td>
                                                           <td width=80 align=center>
                                                               <a href=ProductSort.aspx?type=2&id=<%# DataBinder.Eval(Container.DataItem,"ID")%>>删除</a> 
                                                          </td>
                                                       </tr>
                                                    </ItemTemplate>
                                                 <FooterTemplate>
                                                    </table>
                                                 </FooterTemplate>
                                              </asp:Repeater>
                                         
                                         </td>
                                      </tr>
                                      <tr>
                                        
                                      </tr>
                                 </ItemTemplate>
                            <FooterTemplate>
                               </table>
                            </FooterTemplate>
                        </asp:Repeater>
                   </td>
                </tr>
                <td height=15px; style="border-style:none;"> </td>
           </ItemTemplate>
           <FooterTemplate>
            </table>
           </FooterTemplate>
        </asp:Repeater>

后台。aspx.cs

    protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rpt2 = (Repeater)e.Item.FindControl("rpt2");
            //找到分类Repeater关联的数据项 
            DataRowView rowv = (DataRowView)e.Item.DataItem;
            rpt2.ItemDataBound += new RepeaterItemEventHandler(rpt2_ItemDataBound); //最最重要的一句
            //提取分类ID 
            cid = Convert.ToInt32(rowv["ID"]);
            //根据分类ID查询该分类下的产品,并绑定产品Repeater 
            rpt2.DataSource = Pcategory.getP(cid);//数据绑定
            rpt2.DataBind();
        }
    }
    protected void rpt2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rpt3 = (Repeater)e.Item.FindControl("rpt3");
            //找到分类Repeater关联的数据项 
            DataRowView rowvv = (DataRowView)e.Item.DataItem;
            //提取分类ID 
            cid2 = Convert.ToInt32(rowvv["ID"]);
            //根据分类ID查询该分类下的产品,并绑定产品Repeater 
            rpt3.DataSource = getrpt3(cid, cid2);//数据绑定
            rpt3.DataBind();
        }
    }

repeater三级嵌套绑定

标签:

原文地址:http://www.cnblogs.com/mjlblog/p/4548479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!