使用dropdownlist的繫結_實現省市列表級聯
阿新 • • 發佈:2019-01-01
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sql = "select * from province";
DataTable dt = SQLHelper.ExecuteDataTable(sql);
this.DropDownListProvince.DataSource = dt;
this.DropDownListProvince.DataValueField = "PId";
this.DropDownListProvince.DataTextField = "Provinces";
this.DropDownListProvince.DataBind();
}
}
protected void DropDownListProvince_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListCity.Items.Clear();
int dr =int.Parse(DropDownListProvince.SelectedValue);
string sql="select * from city where [email protected]";
SqlParameter[] pms = new SqlParameter[] { new SqlParameter("@pid", dr) };
DataTable dt=SQLHelper.ExecuteDataTable(sql,pms);
this.DropDownListCity.DataSource = dt;
this.DropDownListCity.DataValueField = "CId";
this.DropDownListCity.DataTextField = "Citys";
this.DropDownListCity.DataBind();
}
{
if (!IsPostBack)
{
string sql = "select * from province";
DataTable dt = SQLHelper.ExecuteDataTable(sql);
this.DropDownListProvince.DataSource = dt;
this.DropDownListProvince.DataValueField = "PId";
this.DropDownListProvince.DataTextField = "Provinces";
this.DropDownListProvince.DataBind();
}
}
protected void DropDownListProvince_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListCity.Items.Clear();
int dr =int.Parse(DropDownListProvince.SelectedValue);
string sql="select * from city where
SqlParameter[] pms = new SqlParameter[] { new SqlParameter("@pid", dr) };
DataTable dt=SQLHelper.ExecuteDataTable(sql,pms);
this.DropDownListCity.DataSource = dt;
this.DropDownListCity.DataValueField = "CId";
this.DropDownListCity.DataTextField = "Citys";
this.DropDownListCity.DataBind();
}