当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How do i make changes of one dropdownlist reflect on other dropdown list in asp.net?

问题描述:

I have two dropdown lists. One is showing emp_id , while the other is showing emp_name.

Both lists use the same sql data source which queries as :

select emp_id , emp-name from emp_table

How do i make changes of one dropdownlist reflect on other?

Say, if i select emp-id, then corresponding emp_name should be selected automatically and vice versa. How can we do that?

I have used SqlDataSource from toolbox and have not configured it manually through code. I am passing a stored procedure which returns emp_name and emp_id from emp_table.

This is simple asp.net project and no mvc has been used.

网友答案:

Use this setup:

  1. Use the emp_id as the value for both drop downs.

  2. Add a SelectedIndexChange event handler for both drop downs. In the event handler, get the emp_id value and set the selected value of the other drop down to the same emp_id.

  3. Set properties Autopostback=true and CausesValidation=false for both drop down.

网友答案:

Below are the steps:

  1. Bind both dropdown with value = emp_id and text = emp_name
  2. onchange event of dropdown1, call a javascript function having below code $('#dropdown2').val($('#dropdown2').val());
分享给朋友:
您可能感兴趣的文章:
随机阅读: