Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an asp.net application. In a page named "default.aspx" there is a category dropdown .After selecting a category I want to load subcategory in another dropdown by querying the database with the selected value of that category dropdown.

query is "select catid from catTable where maincat="+selected value of category.

the javascript function which call json is "loadsub()" is in page default.aspx.



my page method is in another page named "ajaxcall.aspx".In that page there is a function named loadAllSub().



Now my question is how to do the job?Just paste the code how to do it.
Posted
Comments
Kornfeld Eliyahu Peter 22-Sep-14 7:48am    
$(function() {
$("#dropdwon1").change(function() {
$("#dropdwon2")[0].selectedIndex = $(this)[0].selectedIndex;
});
});​
souvikcode 22-Sep-14 10:14am    
actually I have to query in database on selected value of 1st dropdown
jkirkerx 22-Sep-14 14:12pm    
You pass the value of the first dropdown using javascript and ajax to the server and return back a json array of name/value back and use that to populate the next dropdown.

Or you can use an update panel and do it in code behind.

Which method would you like us to write your code for?
souvikcode 25-Sep-14 9:49am    
1)your solutions are fine.If I return array,then it can be bound in dropdown. But may I pass a control in json function?
In c# function we can write
private void bindDropdown(dropdownlist drp)
{}
and can pass my dropdown as parameter.
2)I can manage it with update panel in code.But I want to know that will it be as fast as doing by json?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900