Use the Repeater control to display master-slave relational data tables)

Source: Internet
Author: User

This section describes how to use the Repeater control to display master-slave relational data tables.

See: http://support.microsoft.com/default.aspx? SCID = KB; en-US; 306154

Nestedrepeater. aspx

 

<% @ Import namespace="System. Data"  %>
<% @ Page Language = " C # " Codebehind = " Nestedrepeater. aspx. CS "  
Autoeventwireup = " False " Inherits = " Emeng. nestedrepeater "   %>
< Html >
< Body >
< Form Runat = "Server" >
<! -- Parent repeater starts -->
< ASP: Repeater ID = "Parentrepeater" Runat = "Server" >
< Itemtemplate >
< B >
<% # Databinder. eval (container. dataitem,"Au_id") %>
</ B >
< BR >
<! -- Subrepeater starts -->
< ASP: Repeater ID = "Childrepeater" Runat = "Server"  
Datasource = '<% # (Datarowview) container. dataitem). Row. getchildrows ("myrelation") % > '>
< Itemtemplate >
<% # Databinder. eval (container. dataitem,"[\"Title_id\"]") %>
< BR >
</ Itemtemplate >
</ ASP: Repeater >
<! -- Subrepeater ends -->
</ Itemtemplate >
</ ASP: Repeater >
<! -- Parent repeater ends -->
</ Form >
</ Body >
</ Html >


Nestedrepeater. aspx. CS

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 Emeng
{
/**//// 
///Brief description of nestedrepeater.
///This topic describes how to use the Repeater control to display a master-slave table.
///For more information, 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 and fill dataset.
Dataset DS =   New Dataset ();
Limit 1.fill (DS, " Authors " );

// Create a dataadapter for the titles table
Sqldataadapter cmd2 =   New Sqldataadapter ( " Select * From titleauthor " , CNN );
Limit 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 parent Repeater
Parentrepeater. datasource = DS. Tables [ " Authors " ];
Page. databind ();

CNN. Close ();
CNN. Dispose ();
}
Private   Void Page_init ( Object Sender, eventargs E)
{
Initializecomponent ();
}
Private   Void Initializecomponent ()
{
This. Load+ = NewSystem. eventhandler (This. Page_load );
}
Public Nestedrepeater ()
{
Page. init+ = NewSystem. eventhandler (page_init );
}
}
}

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 27695

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.