1
votes

Can anyone tell me how to populate one listbox from another listbox item using JavaScript or ASP.NET 2.0?

Duplicate

How would I move one list box items to another listbox items in JavaScript?

For ex--My 1st listbox is Region then accourding to region selection the second listbox country will be display and accourding to country seletion state listbox will display all will come from database depends on Region Id or Country id n all

2
More detail on what you need, please. What do you want the other list box populated with? Where does this data come from?tvanfosson
For ex--My 1st listbox is Region then accourding to region selection the second listbox country will be display and accourding to country seletion state listbox will display all will come from database depends on Region Id or Country id n allpriti

2 Answers

1
votes

You may be interested in the 'Cascading Dropdown' control from the ASP.net AJAX Control Toolkit. http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

You could also probably do this without the toolkit, using the standard UpdatePanel from ASP.net AJAX and specifing the "onChange" event of the first dropdown as a "trigger" for that UpdatePanel to be updated. Be sure you set AutoPostback="true" on the dropdown so it is fired properly is you go this route also.

0
votes

Your question leaves out a lot of detail, but basically you would wire a function to the onchange event of the first listbox, that would populate the second listbox. If the contents would need to be dynamically loaded, you would then need to use AJAX (or similar) to pull them from the server and push them into the second box; alternatively if your contents are statically defined and not too weighty, it would be more responsive to serve them with the original document (perhaps as an associative array keyed on the values of the first listbox) and then update the second listbox based on an array lookup.