Public partial class _ Default: System. Web. UI. Page
{
Protected string title = "Hello everyone"; // front-end Code <title> <% # title %> </title>
Protected void Page_Load (object sender, EventArgs e)
{
DataSet ds = new DataSet ();
String SQL = ConfigurationManager. ConnectionStrings ["strsql"]. ConnectionString;
Using (SqlConnection sqlCnn = new SqlConnection (SQL ))
{
Using (SqlCommand sqlCmm = sqlCnn. CreateCommand ())
{
SqlCmm. CommandText = "select * from List ";
SqlDataAdapter adapter = new SqlDataAdapter (sqlCmm );
Adapter. Fill (ds );
}
This. RadioButtonList1.DataSource = ds. Tables [0];
This. RadioButtonList1.DataTextField = "listname ";
This. RadioButtonList1.DataValueField = "id ";
// This. RadioButtonList1.DataBind ();
This. CheckBoxList1.DataSource = ds. Tables [0];
This. CheckBoxList1.DataTextField = "listname ";
This. CheckBoxList1.DataValueField = "id ";
// This. RadioButtonList1.DataBind ();
This. DataBind ();
} // Bind data to RadioButtonList and CheckBoxList
If (! IsPostBack)
{
DataSet ds1 = new DataSet ();
Using (SqlConnection sqlCnn1 = new SqlConnection (SQL ))
{
Using (SqlCommand sqlcmcm1 = sqlCnn1.CreateCommand ())
{
Sqlcmcm1.commandtext = "select provinceid, provincename from Province ";
SqlDataAdapter adapter = new SqlDataAdapter (sqlcmcm1 );
Adapter. Fill (ds1 );
This. DropDownList1.DataSource = ds1.Tables [0];
This. DropDownList1.DataTextField = "provincename ";
This. DropDownList1.DataValueField = "provinceid ";
This. DropDownList1.DataBind ();
}
}
}
}
Protected void dropdownlistincluselectedindexchanged (object sender, EventArgs e)
{
DataSet ds = new DataSet ();
String str = ConfigurationManager. ConnectionStrings ["strsql"]. ConnectionString;
Using (SqlConnection sqlCnn = new SqlConnection (str ))
{
Using (SqlCommand sqlCmm = sqlCnn. CreateCommand ())
{Www.2cto.com
SqlCmm. CommandText = "select cityid, cityname from City where provinceid = '" + this. DropDownList1.SelectedValue + "'";
SqlDataAdapter adapter = new SqlDataAdapter (sqlCmm );
Adapter. Fill (ds );
This. DropDownList2.DataSource = ds. Tables [0];
This. DropDownList2.DataTextField = "cityname ";
This. DropDownList2.DataValueField = "cityid ";
This. DropDownList2.DataBind ();
}
}
} // Implement provincial/municipal level-2 Linkage
}
From haitaoDoit