Datalist nested datalist
1. html Code < Html >
< Head >
< Title > Nesteddatalists </ Title >
< Meta Name = "Generator" Content = "Microsoft Visual Studio. net7.1" >
< Meta Name = "Code_language" Content = "C #" >
< Meta Name = "Vs_defaultclientscript" Content = "JavaScript" >
< Meta Name = "Vs_targetschema" Content = "Http://singlepine.cnblogs.com /" >
</ Head >
< Body Ms_positioning = "Gridlayout" >
< Form ID = "Form1" Method = "Post" Runat = "Server" >
< ASP: datalist Runat = "Server" ID = "Dlcategories" Gridlines = "Both" Bordercolor = "Black" Cellpadding = "3"
Cellspacing = "0" Headerstyle-backcolor = "# Dddddd" Headerstyle-forecolor = "#777777" Headerstyle-font-name = "Arial"
Headerstyle-font-size = "14" Headerstyle-font-bold = "True" Font-name = "Arial" Font-bold = "True"
Font-italic = "True" Font-size = "11" Forecolor = "Red" Repeatcolumns = "1" >
< Headertemplate >
Province, city
</ Headertemplate >
< Itemtemplate >
<% # Databinder. eval (container,"Dataitem. Province") %>
< BR >
< ASP: datalist Runat = "Server" ID = "Childdatalist" Gridlines = "NONE" Bordercolor = "Black" Cellpadding = "3" Cellspacing = "0" Headerstyle-backcolor = "#8080c0" Headerstyle-font-name = "Arial" Headerstyle-font-size = "8" Font-name = "Arial" Font-size = "8" Datasource = '<% # Databinder. eval (container, "dataitem. myrelation") % > 'Repeatcolumns = "5">
< Itemtemplate >
& Nbsp; & Nbsp;
<% # Databinder. eval (container,"Dataitem. City") %>
</ Itemtemplate >
</ ASP: datalist >
</ Itemtemplate >
</ ASP: datalist >
</ Form >
</ Body >
</ Html >
2. CS code Public Class Nesteddatalists: system. Web. UI. Page
{
Protected System. Web. UI. webcontrols. datalist dlcategories;
Private Void Page_load ( Object Sender, system. eventargs E)
{
String Constring = System. configuration. configurationsettings. deleettings [ " Connectionstring " ];
Dataset DS = New Dataset ();
String Sql1 = " Select * From Province " ;
Sqldataadapter sda1 = New Sqldataadapter (sql1, constring );
Sda1.fill (DS, " Province " );
String Sql2 = " Select * from City " ;
Sqldataadapter sda2 = New Sqldataadapter (sql2, constring );
Sda2.fill (DS, " City " );
DS. relations. Add ( " Myrelation " , DS. Tables [ " Province " ]. Columns [ " Provinceid " ], DS. Tables [ " City " ]. Columns [ " Father " ]);
Dlcategories. datasource = DS. Tables [ " Province " ]. Defaultview;
Dlcategories. databind ();
}
Web Form Designer generated code # Region Web Form Designer generated code
Override Protected Void Oninit (eventargs E)
{< br> //
// codegen: This call is required by the ASP. net web form designer.
//
initializecomponent ();
base . oninit (E);
}
/**/ /// <Summary>
///Required Method for designer support-do not modify
///The contents of this method with the code editor.
/// </Summary>
Private Void Initializecomponent ()
{
This. Load+ = NewSystem. eventhandler (This. Page_load );
}
# Endregion
}
Reprinted: http://www.cnblogs.com/jembai/articles/1290660.html