asp.net repeat嵌套(3)

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

<asp:Repeater id="parentRepeater" runat="server">
 <itemtemplate>
  <b>
   <%# DataBinder.Eval(Container.DataItem, "au_id") %>
  </b>
  <br>
  <asp:repeater id="childRepeater" runat="server"
                    datasource='<%# ((DataRowView)Container.DataItem)
      .Row.GetChildRows("myrelation") %>' >
   <itemtemplate>
    <%# DataBinder.Eval(Container.DataItem, "[\"title_id\"]")%><br> 
   </itemtemplate>
  </asp:Repeater>
 </itemtemplate>
</asp:Repeater>
     
6. Add the following page directive to the top of the page:
7. <%@ Import Namespace="System.Data" %>
     
8. In the code-behind page, replace the following line in the Page_Load event
9. //Insert code in step 4 of the next section here.
      
with the following code:
         //Create a second DataAdapter for the Titles table.
         SqlDataAdapter cmd2 = new SqlDataAdapter("select * from titleauthor",cnn);
         cmd2.Fill(ds,"titles");

         //Create the relation between the Authors and Titles tables.
         ds.Relations.Add("myrelation",
         ds.Tables["authors"].Columns["au_id"],
         ds.Tables["titles"].Columns["au_id"]);

     
This adds the Titles table to the DataSet, and then adds the relationships between the Authors and Titles tables.
10. Save and compile the application.
11. View the page in the browser, and then verify that the page works so far. The output should appear as follows:
172-32-1176
PS3333
213-46-8915
BU1032
BU2075
238-95-7766
PC1035
267-41-2394
BU1111
TC7777
...


Complete Code List
Nestedrepeater.aspx
<%@ Page language="c#" Codebehind="NestedRepeater.aspx.cs" AutoEventWireup="false" Inherits="NestedRepeater.NestedRepeater" %>
<%@ Import Namespace="System.Data" %>

<html>
<body>
<form runat=server>

<!-- start parent repeater -->

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

推荐热点

  • 浅析.NET下XML数据访问新机制
  • asp.net 面试+笔试题目第1/2页
  • C# 邮件地址是否合法的验证
  • asp.net 设置GridView的选中行的实现代码
  • C#高级编程:数据库连接[1]
  • ASP.NET&#160;GridView列表代码示例
  • 经典C++程序1
  • 微软ASP.NET站点部署指南(2):部署SQL Server Compact数据库
  • 微软ASP.NET站点部署指南(3):使用Web.Config文件的Transforma
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1