01.
private
void
Page_Load(
object
sender, System.EventArgs e)
02.
{
03.
04.
if
(!Page.IsPostBack)
05.
{
06.
Bindddl1();
07.
Bindddl2();
08.
}
09.
}
10.
11.
private
void
Bindddl1()
12.
{
13.
Conn c =
new
Conn();
14.
DropDownList1.DataSource = c.getProvince();
15.
DropDownList1.DataValueField =
"ProvinceID"
;
16.
DropDownList1.DataTextField =
"ProvinceName"
;
17.
DropDownList1.DataBind();
18.
}
19.
20.
21.
private
void
Bindddl2()
22.
{
23.
Conn c =
new
Conn();
24.
25.
DropDownList2.DataSource = c.getDistrict(Convert.ToInt32(DropDownList1.SelectedItem.Value));
26.
DropDownList2.DataValueField =
"DistrictID"
;
27.
DropDownList2.DataTextField =
"DistrictName"
;
28.
DropDownList2.DataBind();
29.
30.
}
31.
32.
33.
private
void
DropDownList1_SelectedIndexChanged(
object
sender, System.EventArgs e)
34.
{
35.
36.
Bindddl2();
37.
}
38.
39.
40.
41.
-------------------------------------------------------------------------------------
42.
public
DataSet getProvince()
43.
{
44.
string
strconn =
"Server=(local);database=DB_Name;Trusted_Connection=yes"
;
45.
SqlConnection conn =
new
SqlConnection(strconn);
46.
string
strsql =
"select * from province"
;
47.
SqlDataAdapter da =
new
SqlDataAdapter(strsql,conn);
48.
DataSet ds =
new
DataSet();
49.
da.Fill(ds,
"province"
);
50.
return
ds;
51.
}
52.
53.
public
DataSet getDistrict(
int
provinceID)
54.
{
55.
string
strconn =
"Server=(local);database=DB_name;Trusted_Connection=yes"
;
56.
SqlConnection conn =
new
SqlConnection(strconn);
57.
string
strsql =
"select * from district where ProvinceID="
+provinceID;
58.
SqlDataAdapter da =
new
SqlDataAdapter(strsql,conn);
59.
DataSet ds =
new
DataSet();
60.
da.Fill(ds,
"district"
);
61.
return
ds;
62.
}