利用Repeater控件显示主-从关系数据表 (NestedRepeater.aspx.cs)
NestedRepeater.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
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 SNHY
{
/// <summary>
/// NestedRepeater 的摘要说明。
/// </summary>
public class NestedRepeater : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater Repeater1;
private void Page_Load(object sender, System.EventArgs e)
{
//ClassInfo(CID,ClassName,ClassDep)
//Topic(AID,CID,CTitle)
DataSet myds=new DataSet();
string dbFile=(new Common.PageBase()).ConfigTb.Rows[0]["AccessFile"].ToString();
string connstr="provider=microsoft.jet.oledb.4.0;data source="+HttpContext.Current.Server.MapPath(dbFile);
OleDbConnection dbconn=new OleDbConnection(connstr);
OleDbDataAdapter cm1=new OleDbDataAdapter("select * from ClassInfo",dbconn);
cm1.Fill(myds,"CTb");
OleDbDataAdapter cm2=new OleDbDataAdapter("select * from Topic",dbconn);
cm2.Fill(myds,"ATb");
myds.Relations.Add("myrelation",myds.Tables["CTb"].Columns["CID"],myds.Tables["ATb"].Columns["CID"]);
this.Repeater1.DataSource=myds.Tables["CTb"].DefaultView;
this.Repeater1.DataBind();
}
#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
}
}