Datalist nested datalist

Source: Internet
Author: User
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

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.