For your reference:
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
SqlConnection con = new SqlConnection ("server =; database = province; uid = sa; pwd = sa ;");
Con. Open ();
SqlCommand cmd = new SqlCommand ("select * from province", con );
SqlDataReader sdr = cmd. ExecuteReader ();
DropDownList1.DataSource = sdr;
DropDownList1.DataTextField = "proname ";
DropDownList1.DataValueField = "proid ";
DropDownList1.DataBind ();
Con. Close ();
Sdr. Close ();
}
}
Protected voidDropDownList1_SelectedIndexChanged(Object sender, EventArgs e)
{
SqlConnection con = new SqlConnection ("server =; database = province; uid = sa; pwd = sa ;");
Con. Open ();
SqlCommand cmd2 = new SqlCommand ("select * from city where proid =" + DropDownList1.SelectedValue, con );
SqlDataReader sdr2 = pai2.executereader ();
DropDownList2.DataSource = sdr2;
DropDownList2.DataTextField = "cityname ";
DropDownList2.DataValueField = "cityid ";
DropDownList2.DataBind ();
DropDownList2.Visible = true;
Sdr2.Close ();
Con. Close ();
}
Front-end:
<Td class = "td_page"> News Type: </td>
<Td> <asp: DropDownList ID = "dropNewType" runat = "server"> </asp: DropDownList> </td>
Background:
DataTable dt = CDB. FillTable ("select TypeId, TypeContent from [newsTypeTable]");
DropNewType. DataSource = dt;
DropNewType. DataTextField = "typeContent ";
DropNewType. DataValueField = "TypeId ";
DropNewType. DataBind ();