您现在的位置:主页 > 技术中心 > 编程开发 > .net

asp.net repeat嵌套(2)

来源:未知 责任编辑:责任编辑 发表时间:2015-09-16 20:04 点击:

24.          SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors",cnn);
25. 
26.          //Create and fill the DataSet.
27.          DataSet ds = new DataSet();
28.          cmd1.Fill(ds,"authors");
29.          //Insert code in step 4 of the next section here.
30.          //Bind the Authors table to the parent Repeater control, and call DataBind.
31.          parentRepeater.DataSource = ds.Tables["authors"];
32.          Page.DataBind();
33. 
34.          //Close the connection.
35.          cnn.Close();
36.        }
     
NOTE: You may have to modify the database connection string as appropriate for your environment.
37. Save all of the files.
38. In Solution Explorer, right-click the NestedRepeater.aspx, and then click Set As Start Page.
39. On the Build menu click Build Solution to compile the project.
40. View the .aspx page in the browser, and then verify that the page works thus far.

The output should appear as follows:
• 172-32-1176
• 213-46-8915
• 238-95-7766
• 267-41-2394
• ...


Bind to the Child Table
1. In the HTML view of the NestedRepeater.aspx page, locate the following line of code:
2. <b><%# DataBinder.Eval(Container.DataItem, "au_id") %></b><br>
      
Add the following code after this code:
<asp:repeater id="childRepeater" runat="server">
  <itemtemplate>
             <%# DataBinder.Eval(Container.DataItem, "[\"title_id\"]")%><br>
  </itemtemplate>
</asp:repeater>
      
This new code adds a second Repeater control to the ItemTemplate property of the parent Repeatercontrol.
3. Set the DataSource property for the child Repeater control as follows:
4. <asp:repeater ... datasource='<%# ((DataRowView)Container.DataItem)
5.       .Row.GetChildRows("myrelation") %>' >
     
After you set the DataSource property for the child Repeater control, the HTML code for the twoRepeater controls (parent and child) appears as follows:

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • C#高级编程:数据库连接[1]
  • asp.net 设置GridView的选中行的实现代码
  • 经典C++程序1
  • IIS 自动回收导致后台定时器失效的问题解决
  • ASP.NET&#160;GridView列表代码示例
  • 微软ASP.NET站点部署指南(3):使用Web.Config文件
?? - ?? - ÝřŝžľŘÝź - TAGąęÇŠ - RSSśŠÔÄ - ??
Copyright © 2004-2024 上海卓卓网络科技有限公司