Repeater 嵌套使用

页面代码:

<asp:Repeater ID="Repeater1" runat="server">
       <itemtemplate>
       <table>
       <tr>
        <%# DataBinder.Eval(Container.DataItem, "c_name") %><br>
        <asp:Repeater ID="Repeater2" runat="server">
         <itemtemplate>
          <a href='Article_Detile.aspx?Id=<%# DataBinder.Eval(Container.DataItem, "a_id") %>'>
           <%# DataBinder.Eval(Container.DataItem, "a_title") %><br>
          </a>
         </itemtemplate>
        </asp:Repeater>
       </tr>
       </table>
       </itemtemplate>
      </asp:Repeater>

后台程序:
 1 None.gif          public   void  loadclassdata()
 2 ExpandedBlockStart.gif         {
 3InBlock.gif            string connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = '"+Server.MapPath("../DataBase/DB.mdb")+"'";
 4InBlock.gif            string commstr = "select * from tb_class";
 5InBlock.gif
 6InBlock.gif            OleDbConnection conn = new OleDbConnection(connstr);
 7InBlock.gif            OleDbCommand comm = new OleDbCommand(commstr,conn);
 8InBlock.gif            
 9InBlock.gif            DataSet myds = new DataSet();
10InBlock.gif
11InBlock.gif            OleDbDataAdapter myadapter = new OleDbDataAdapter(comm);
12InBlock.gif
13InBlock.gif            try
14ExpandedSubBlockStart.gif            {
15InBlock.gif                myadapter.Fill(myds,"tb_class");
16InBlock.gif                this.Repeater1.DataSource=myds.Tables["tb_class"].DefaultView;
17InBlock.gif                this.Repeater1.DataBind();
18ExpandedSubBlockEnd.gif            }

19InBlock.gif            catch(Exception ex)
20ExpandedSubBlockStart.gif            {
21InBlock.gif                Response.Write(ex.Message);
22ExpandedSubBlockEnd.gif            }

23InBlock.gif            finally
24ExpandedSubBlockStart.gif            {
25InBlock.gif
26ExpandedSubBlockEnd.gif            }

27ExpandedBlockEnd.gif        }

28 None.gif
29 None.gif         private   void  Repeater1_ItemCreated( object  sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
30 ExpandedBlockStart.gif         {
31InBlock.gif            object cid;
32InBlock.gif            cid = DataBinder.Eval(e.Item.DataItem,"c_id");            
33InBlock.gif            Repeater Repeater2;
34InBlock.gif            Repeater2=(Repeater)e.Item.FindControl("Repeater2");
35InBlock.gif            string connstr="Provider = Microsoft.Jet.OLEDB.4.0;Data Source = '"+Server.MapPath("../DataBase/DB.mdb")+"'";
36InBlock.gif            string commstr = "select * from tb_article";
37InBlock.gif            OleDbConnection conn=new OleDbConnection(connstr);
38InBlock.gif            OleDbCommand cmd=new OleDbCommand(commstr,conn);
39InBlock.gif            OleDbDataAdapter da=new OleDbDataAdapter(cmd);
40InBlock.gif            DataSet ds=new DataSet();
41InBlock.gif            da.Fill(ds,"tb_article");
42InBlock.gif            Repeater2.DataSource=ds.Tables["tb_article"].DefaultView;
43InBlock.gif            Repeater2.DataBind();
44ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/guodapeng/archive/2006/10/08/523710.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值