问题描述:

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());
相关阅读:
Top