asp.net DataList linkage level two menu binding data

Source: Internet
Author: User

This example is about the use of DataList data-bound controls, because I was just learning this dongdong, so there is a wrong place to ask you advice ah.
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");

That's the key, it seems, to create a relationship between 2 tables by ID, and then load the data
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 () NOT NULL

)

  Create Table son

(

son_id ID NOT null primary key, primary key tid    

  So N_name varchar null,    

  partent_id not null  //partent associated with id

)

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.