?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
??? ??? ??????? ?? ???? ??? It opens in Design View in the
Integrated Development Environment (IDE) of Microsoft Visual Studio .NET. From
the Toolbox, select theRepeatercontrol, and then drag it to the Web Form page.
????????? ????IDproperty of thisRepeater???? ?? ??? ????????parentRepeater.
Switch to the HTML view for this Web Form. ??? ???? ?? ???, ????? ????htmltab in the lower-left corner of the Designer. TheRepeatercontrol generates the following HTML code:
?????? Explorer ???, ???? ?????NestedRepeater.aspx?? ????-????? ????, ?? ???? ???????? ???to switch to the NestedRepeater.aspx.cs code-behind
file.
Add the following namespace declaration to the top of the
file:
using System.Data;
using System.Data.SqlClient;
????? ??? ??????Page_Loadevent to create a connection to thePubs???????, ?? ??? ????? ???? ?? ????????????? ?? ??? ??????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; Integrated Security=SSPI");
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from authors",cnn);
//Create and fill the DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds,"authors");
//Insert code in step 4 of the next section here.
//Bind the Authors table to the parent Repeater control, and call DataBind.
parentRepeater.DataSource = ds.Tables["authors"];
Page.DataBind();
//Close the connection.
cnn.Close();
}
//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"]);
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace NestedRepeater
{
public class NestedRepeater : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater parentRepeater;
public NestedRepeater()
{
Page.Init += new System.EventHandler(Page_Init);
}
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; Integrated Security=SSPI ;");
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.
parentRepeater.DataSource = ds.Tables["authors"];
Page.DataBind();
//Close the connection.
cnn.Close();
}
private void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}