Click here to Skip to main content
15,894,240 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all in my project I populate dropdownlist using javascript but when I submit always the selected value of the dropdown is 0 what can I do to submit the javascript populated data
here is my code
C#
<asp:DropDownList ID="ListModel" runat="server" ClientIDMode="Static" ></asp:DropDownList>


JavaScript
success: function (Result) {
           Result = Result.d;
           var parsedData = JSON.parse(Result);
           $("#ListModel").empty();
           for (var i = 0; i < parsedData.length+1; i++) {
               //alert(parsedData[i].Id + parsedData[i].Name);
               //var opt = document.createElement("option");
               //opt.value = parsedData[i].Id;
               //opt.text = parsedData[i].Name;
               $("#ListModel").append($('<option><option/>').val(parsedData[i].Id).html(parsedData[i].Name));

           }


Please Help
Posted

1 solution

You can't change an asp:Dropdownlist via javascript and have the control know about those changes when you post back. If you want to manipulate the select on the client then use a normal <select> tag rather than an asp:Dropdownlist

http://stackoverflow.com/questions/18662019/c-asp-net-repeater-with-a-html-select[^]
 
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