Asp.net DataList associates two-level menu Binding data

Source: Internet
Author: User

In this example, we will talk about using datalist to bind controls. Because I just learned this stuff, please give me some advice.
Asp tutorial. net code

Private void dataload ()

{

Dataset ds = new dataset ();

String SQL = "select * from partent ";

Sqlconnection con = new sqlconnection ("data source = pc-200912151837; initial catalog = test; integrated security = true ");

Sqldataadapter da = new sqldataadapter (SQL, con );

Da. fill (ds, "xinghao ");
String sql2 = "select * from parent ";

Sqldataadapter da2 = new sqldataadapter (sql2, con );

Da2.fill (ds, "parent ");

// This sentence is the most important. It seems that the relationship between two tables is established by id, and then the data is loaded.
Ds. relations. add ("myreation", ds. tables ["son"]. columns ["son_id"], ds. tables ["parent"]. columns ["parent_id"]);

Datalist. datasource = ds. tables ["son"]. defaultview;

Datalist. databind ();

}


 

Database tutorial code:

  

Create table partent

(Partent_id int not null primary key, primary key id

Partent_name varchar (50) not null

)

Create table son

(

Son_id id not null primary key, primary key tid

Son_name varchar (50) not null,

Partent_id not null // id associated with partent

)

Related Article

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.