Implement level-2 linkage menu C # with complete database SQL

Source: Internet
Author: User

---------------- Db. cs ------------------------------

// TODO: add the constructor logic here
//
}
Public static SqlConnection createConnection ()
{
SqlConnection con = new SqlConnection ("server =.; database = list; uid = sa; pwd = ;");
Return con;
}
}
}


--------------------------. Cs source file --------------------------------

Private void Page_Load (object sender, System. EventArgs e)
{
If (! Page. IsPostBack)
{
SqlConnection con = db. createConnection ();
Con. Open ();
SqlCommand cmd = new SqlCommand ("select * from sheng", con );
SqlDataReader sdr = cmd. ExecuteReader ();
This. sheng. DataSource = sdr;
This. sheng. DataTextField = "sheng ";
This. sheng. DataValueField = "shengid ";
This. sheng. DataBind ();
Sdr. Close ();
Cmd. CommandText = "select * from city where shengid = 1 ";
Sdr = cmd. ExecuteReader ();
This. city. DataSource = sdr;
This. city. DataTextField = "cityname ";
This. city. DataValueField = "cityid ";
This. city. DataBind ();
Sdr. Close ();
Con. Close ();
}
}
# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. sheng. SelectedIndexChanged + = new System. EventHandler (this. DropDownList1_SelectedIndexChanged );
This. Button1.Click + = new System. EventHandler (this. button#click );
This. Calendar1.SelectionChanged + = new System. EventHandler (this. calendar#selectionchanged );
This. rdl. SelectedIndexChanged + = new System. EventHandler (this. drl_SelectedIndexChanged );
This. mar. SelectedIndexChanged + = new System. EventHandler (this. mar_SelectedIndexChanged );
This. Load + = new System. EventHandler (this. Page_Load );

}
# Endregion

Private void button#click (object sender, System. EventArgs e)
{

}
Private void dropdownlistpolicselectedindexchanged (object sender, System. EventArgs e)
{
SqlConnection con = db. createConnection ();
Con. Open ();
SqlCommand cmd = new SqlCommand ("select * from city where shengid =" + this. sheng. SelectedValue. ToString (), con );
SqlDataReader sdr = cmd. ExecuteReader ();
This. city. DataSource = sdr;
This. city. DataTextField = "cityname ";
This. city. DataValueField = "cityid ";
This. city. DataBind ();
Sdr. Close ();
Con. Close ();
}

----------------------- SQL file -----------------------

Create database list

Use list

Create table sheng
(
Shengid int primary key,
Sheng varchar (50) not null,
)

Insert into sheng values (1, 'sichuan ')
Insert into sheng values (2, 'anhui ')
Insert into sheng values (3, 'henan ')
Insert into sheng values (4, 'chongqing ')
Insert into sheng values (5, 'guangxi ')

Select * from sheng

Create table city
(
Cityid int primary key,
Shengid int foreign key references sheng (shengid ),
Cityname varchar (50) not null,
)

Insert into city values (1, 1, 'chengdu ')
Insert into city values (2, 1, 'mianyang ')
Insert into city values (3, 1, 'guangyuan ')
Insert into city values (4, 2, 'hefei ')
Insert into city values (5, 2, 'bengbu ')
Insert into city values (6, 2, 'huainan ')
Insert into city values (7,3, 'zhengzhou ')
Insert into city values (8, 3, 'kaifeng ')
Insert into city values (10, 3, 'shangqiu ')
Insert into city values (11,4, 'dianjiang ')
Insert into city values (12, 4, 'jiangjin ')
Insert into city values (13, 4, 'chongqing ')
Insert into city values (14,5, 'nanning ')
Insert into city values (15,5, 'liuzhou ')
Insert into city values (16, 5, 'White ')

Select * from city

--------- If a friend learns to use it, it is better to see clearly. I write while doing it, but it is not a successful execution ------

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.