Use the Repeater control to display master-slave relational data tables
Source: Internet
Author: User
NestedRepeater. aspx
NestedRepeater. aspx. csusing 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 eMeng
{
///
/// Brief description of NestedRepeater.
/// This article describes how to use the Repeater control to display the master-slave relationship table.
// For the original article, see:
/// Http://support.microsoft.com/default.aspx? Scid = kb; en-us; 306154
///
Public class NestedRepeater: System. Web. UI. Page
{
Protected System. Web. UI. WebControls. Repeater parentRepeater;
Public void Page_Load (object sender, EventArgs e)
{
// Create a Connection and DataAdapter for the Authors table
String cnnString = @ "server = (local) NetSDK; database = pubs; Integrated Security = SSPI ;";
SqlConnection cnn = new SqlConnection (cnnString );
SqlDataAdapter cmd1 = new SqlDataAdapter ("select * from authors", cnn );
// Create a filled DataSet.
DataSet ds = new DataSet ();
Statement 1.fill (ds, "authors ");
// Create a DataAdapter for the Titles table
SqlDataAdapter cmd2 = new SqlDataAdapter ("select * from titleauthor", cnn );
Listen 2.fill (ds, "titles ");
// Create the relationship between the Authors table and the Titles table.
Ds. Relations. Add ("myrelation ",
Ds. Tables ["authors"]. Columns ["au_id"],
Ds. Tables ["titles"]. Columns ["au_id"]);
// Bind Authors to the parent Repeater
ParentRepeater. DataSource = ds. Tables ["authors"];
Page. DataBind ();
Cnn. Close ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.