Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two dropdownlist in every cell of rows of gridview , i want to bind bind second drropdown based on selected value of first dropdown, with second dropdonw bind should be same cell in which first downdownn keep and select ,plz give me any idea how to developed
Posted
Updated 17-Sep-13 20:19pm
v2

1 solution

To avoid server side postbacks, use jquery to get the current dropdown's selected item, and based on that, use ajax to bind the second dropdown.
As this dropdown will be within a grid and the id generated dynamically, we need to use ClientID to get the referred dropdown.

ASP.NET
<templatecolumn>
<itemtemplate>
<asp:dropdown id="ddl_main" runat="server" ...="" onchange="javascript:ddl_MainUpdated('#' + '<%ddl_main.ClientID%>', '#' + '<%ddl_child.ClientID%>' );" xmlns:asp="#unknown" />   
<asp:dropdown id="ddl_child" runat="server" xmlns:asp="#unknown" />
</itemtemplate>
</templatecolumn>


javascript

JavaScript
function ddl_MainUpdated(mainDdlId, childDdlId) {
    var selectedItem = $(mainDdlId + ' option:selected').text();   // or val
    var listOfDependentItem = AjaxCall(selectedItem)  // this will be ajax method.... and will return an array of items.. <this is="" just="" set="" the="" items="" within="" ajax="" method="" itself="">
    listOfDependentItem.each( function (index) { childDdlId.append( $(this).value ) } );</this>


Please note that this is just an illustration of how code would work.
 
Share this answer
 

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