Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在下拉列表中有选择地显示项目_Jquery_Asp.net - Fatal编程技术网

Jquery 在下拉列表中有选择地显示项目

Jquery 在下拉列表中有选择地显示项目,jquery,asp.net,Jquery,Asp.net,我有两个下拉列表-DDL公司和DDL联系人 让我们说- Companies | Company A | Company B | Company C | ----------|-----------|-----------|-----------| Contacts | Albo | Bill | Charlie | | Alex | Bob | Chad | | Aaron | Brad

我有两个下拉列表-DDL公司和DDL联系人

让我们说-

Companies | Company A | Company B | Company C |
----------|-----------|-----------|-----------|
Contacts  | Albo      | Bill      | Charlie   |
          | Alex      | Bob       | Chad      |
          | Aaron     | Brad      | Dennis    |
在我的公司名单中——A公司、B公司和C公司 在ddlContacts中,我加载所有联系人,Alex、bob、chad

现在在用户控件中,我只想显示那些属于所选公司(ddlContacts0)的名称

编辑:
加载下拉列表的代码

ddlCompanies.DataSource = companies; //companies is instance of  IEnumerable<ListItem>
//Also the text of the list item is the name of the company, and value is the ID
ddlCompanies.DataTextField = "Text";
ddlCompanies.DataValueField = "Value";
ddlCompanies.DataBind();
ddlCompanies.DataSource=companys;//companys是IEnumerable的实例
//此外,列表项的文本是公司名称,值是ID
ddlCompanies.DataTextField=“Text”;
ddlCompanies.DataValueField=“Value”;
ddlCompanies.DataBind();
联系人代码

ddlContacts.DataSource = allContacts // all contacts is instance of IEnumerable<ListItem> and contains all the contacts for all companies.  
//The text Value Contains the name of the employee, and value is the ID
//If needed, I can look up the company for the contact in the code behind.
ddlContacts.DataTextField = "Text";
ddlContacts.DataValueField = "Value";
ddlContacts.DataBind();
ddlContacts.DataSource=allContacts//all contacts是IEnumerable的实例,包含所有公司的所有联系人。
//文本值包含员工的姓名,值为ID
//如果需要,我可以在“代码隐藏”中查找公司联系人。
ddlContacts.DataTextField=“Text”;
ddlContacts.DataValueField=“Value”;
ddlContacts.DataBind();
有人能帮我吗-


谢谢,

我将使用ASP.NET编写一些JavaScript(带有
标记)

这些信息是从数据库中提取出来的,并通过ASP.NET像这样写入
标记中的页面

现在,只要
ddlCompanies
发生更改,就可以使用jQuery来实现这一点,调用一个函数,该函数使用所选的
ddlCompanies
值来决定要使用
contacts
数组中的哪个元素。然后,它拆分此字符串并将所有项目放入
ddlcompancts


我不会在这里尝试编写准确的代码,因为我可能会出错。如果您无法使其为您工作,请发表评论。

我在周末回答了一个类似的问题,可能会有所帮助-过滤标准是什么?当公司发生变化时,你是否需要从数据库中获取联系人,或者你是否加载了所有公司的所有联系人,并以某种方式加以区分?@JamesJohnson我将公司和联系人加载到页面加载中。这并不能真正回答我的问题。“联系人”下拉列表中是否加载了所有公司的联系人?请发布下拉列表的标记以及其他相关内容。有很多方法可以做到这一点。
var contacts;
contacts['A'] = 'Albo,Alex,Aaron';
contacts['B'] = 'Bill,Bob,Brad';
contacts['C'] = 'Charlie,Chad,Dennis';