Repeater控件嵌套,测试通不过

sunnystroller 2005-01-28 02:15:26
借鉴:
http://dev.csdn.net/develop/article/29/29697.shtm

就是通不过

//************************************************************************
<%@ Page language="c#" Codebehind="testaspx.aspx.cs" AutoEventWireup="false" Inherits="Tonglang.testaspx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>testaspx</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<!-- 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 -->
</FONT>
</form>
</body>
</HTML>
//************************************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Tonglang
{
/// <summary>
/// testaspx 的摘要说明。
/// </summary>
public class testaspx : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater parent;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//Create the connection and DataAdapter for the Authors table.
SqlConnection cnn = new SqlConnection("server=(local);database=pubs;uid=sa;pwd=sa;");
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();
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
报错如下:

编译器错误信息: CS0246: 找不到类型或命名空间名称“DataRowView”(是否缺少 using 指令或程序集引用?)

真是奇怪,我看了好多相关的资料都是这样写的,孟兄的我也看了,http://dotnet.aspx.cc/ShowDetail.aspx?id=54F4C732-AAE2-4135-FB1B-7B4B613BAA33

我没有发现我有什么错误,怎么就是通不过啊?
请高手指点!谢谢!!

...全文
84 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
srz007 2005-01-28
  • 打赏
  • 举报
回复
我不太喜欢这种嵌套的方式,当数据库中的数据某一条没有相应的父记录时,会报错
你应该在父repeater的item_DataBound事件中创建子repeater,这样才不会出问题

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧