问题描述
尊敬的专家!
正在使用asp.net,C#,Sqlserver2005
我有两个Dropdownlists ...... Dropdownlist1和Dropdownlist 2
在第一个下拉列表中显示公司列表.....在第二个下拉列表中显示部门.
这两个将来自数据库.
假设当用户从第一个下拉列表中选择公司时,在另一个下拉列表中应显示与该公司相关的部门.
请帮我怎么做.
谢谢.
Dear Experts !!
am working on asp.net,C#,Sqlserver2005
I have Two Dropdownlists.... Dropdownlist1 and Dropdownlist 2
In first dropdownlist it shows list of companies..... in second dropdownlist it shows Departments.
These two will comes from database.
Suppose when the user select the company from 1st dropdownlist so,in the other dropdownlist it should show related departments to that company.
Please help me how to do this.
Thanks.
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillDropDownList();
}
}
使公司下拉自动回发为真.
Make company drop down Auto postback true.
private void FillDropDownList()
{
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select company FROM Tablename", connection Object);
myda.Fill(ds);
drop_company.DataSource = ds;
drop_company.DataValueField = "company";
drop_company.DataBind();
drop_company.Items.Insert(0, new ListItem("Select", "0"));
}
双击公司的DropDown.
Double click on Company`s DropDown.
protected void drop_company_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("Select department FROM tablename where company=''"+drop_company.SelectedItem.Value+"''",connection_Object);
myda.Fill(ds);
drop_dept.DataSource = ds;
drop_dept.DataValueField = "department";
drop_dept.DataBind();
drop_dept.Items.Insert(0, new ListItem("Select", "0"));
}
希望这会对您有所帮助,如果没有的话,请张贴它.
Hope This will Help You, if not please Post it.
这篇关于如何从下拉列表中选择数据并在另一个下拉列表中显示特定记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!