本文介绍了如何将DropdownList绑定到另一个DropdownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
祝你有个美好的一天!!
我有两个DROPDOWNLISTS Webform和我想要彼此绑定。
假设我从大学下拉列表中选择CollegeName ...而另一个应该显示该特定学院的部门。
请你建议我怎么做?
谢谢ADVANCE。
Dear Friends,
Have a Good Day !!
I have Two DROPDOWNLISTS on my Webform and I want to Bind Each Other.
Suppose if I select CollegeName from College Dropdownlist...and the Other one Should Display the Departments of that Particular College.
Please can u suggest me how to do this ?
Thanks in ADVANCE.
推荐答案
if (!IsPostBack)
{
FillDropDownList();
}
private void FillDropDownList()
{
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select college FROM tablename",connection object);
myda.Fill(ds);
drop_college.DataSource = ds;
drop_college.DataValueField = "college";
drop_college.DataBind();
drop_college.Items.Insert(0, new ListItem("Select", "0"));
}
then after double click on college Dropdown.
protected void drop_college_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select department FROM tablename where college='"+drop_college.SelectedItem.Value+"'", connection object);
myda.Fill(ds);
drop_department.DataSource = ds;
drop_department.DataValueField = "department";
drop_department.DataBind();
drop_department.Items.Insert(0, new ListItem("Select", "0"));
}
Hope this will help You.
这篇关于如何将DropdownList绑定到另一个DropdownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!