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