前台应用----------嵌套repeater控件

本文介绍了一种多层次数据展示的技术方案,包括使用存储过程获取不同层级的数据,并通过ASP.NET Repeater控件实现数据的动态绑定。此外,还展示了如何在DataBind事件中利用findcontrol方法定位子控件并对其进行数据绑定。

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

Introduce:
         多个大类。每个大类推荐几个子内容
          如   种类一
                           列1,列2,列3
                  种类二
                           列1,列2,列3
usein:
         新闻中,使用不同模块,每个模块推荐几个新闻.
         留言中,取前几个有回复内容的主题,每个主题再取对应的几个回复内容
sql:
        两个存储过程,一,取大类信息,二,通过大类的parentId,取子列表
原理:
      一. 在DataBind事件中  使用findcontrol 把子控件找出来,再对他进行,BindUcDataSet( ParentId)
      二. 在已经存在的大数据表中, 使用表的 过滤功能绑定数据
 
        
        
方法二,前台部分
<!-- start parent repeater -->
<asp:repeater id="parent" runat="server">
  <itemtemplate>
   <b><%# DataBinder.Eval(Container.DataItem,"au_id") %></b><br>
   <!-- start child repeater -->
   <asp:repeater id="child" datasource=’<%# ((DataRowView)Container.DataItem)
.Row.GetChildRows("myrelation") %>’ runat="server">
    <itemtemplate>
      <%# DataBinder.Eval(Container.DataItem, "["title_id"]")%><br>
     </itemtemplate>
   </asp:repeater>
   <!-- end child repeater -->
 </itemtemplate>
</asp:repeater>
<!-- end parent repeater -->
 public void Page_Load(object sender, EventArgs e)   {     //Create the connection and DataAdapter for the Authors table.     SqlConnection cnn = new SqlConnection("server=(local);database=pubs;uid=sa;pwd=;");     SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors",cnn);
     
//Create and fill the DataSet.     DataSet ds = new DataSet();     cmd1.Fill(ds,"authors");
     
//Create a second DataAdapter for the Titles table.     SqlDataAdapter cmd2 = new SqlDataAdapter("select * from titleauthor",cnn);     cmd2.Fill(ds,"titles");
     
//Create the relation bewtween the Authors and Titles tables.     ds.Relations.Add("myrelation",     ds.Tables["authors"].Columns["au_id"],     ds.Tables["titles"].Columns["au_id"]);
     
//Bind the Authors table to the parent Repeater control, and call DataBind.     parent.DataSource = ds.Tables["authors"];     Page.DataBind();
     
//Close the connection.     cnn.Close();   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值