如何从下拉列表中选择数据并在另一个下拉列表中显示特定记录 [英] How to select the data from dropdownlist and display that particular records in another dropdown list

查看:96
本文介绍了如何从下拉列表中选择数据并在另一个下拉列表中显示特定记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的专家!

正在使用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.

推荐答案

您可以使用以下内容:
you can use following things:
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.


Country ,State and City DropDownList in ASP.NET[^]




Try this one...


这篇关于如何从下拉列表中选择数据并在另一个下拉列表中显示特定记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆