-5

I have Bind asp.net dropDwon by Jquery ajax Call .now i want selected text from code behind. How?

                    <asp:DropDownList runat="server" ID="DropdownCounty" DataValueField="id" DataTextField="name" AppendDataBoundItems="True" onchange="populateState();">

                    </asp:DropDownList>

                    $.ajax({
                        type: "POST",
                        url: "webservice/WebService1.asmx/getCountry",
                        contentType: "application/json; charset=utf-8",  
                        dataType: 'JSON',
                        success: function (response) {

                            $("#DropdownCounty").empty();
                            $("#DropdownCounty").append('<option value="0">Please select</option>');
                            $.each(response.d, function (key, value) {
                                $("#DropdownCounty").append($("<option></option>").val(value.id).text(value.name));
                            })
                                },
                        failure: function (response) {

                            alert(response.d);
                        }

                    });

Code behind

var dasd = DropdownCounty.SelectedValue;

  • 1
    AJAX doesn't bind anything, AJAX is for making HTTP requests. Please read [ask] and [edit] your question so that it makes sense. – Camilo Terevinto Jul 06 '18 at 12:11
  • My guess, **you** **should** **consider** **editing** **your** **question** **to** **help** **people** **understand** **it**, is that you dont know how to get using javascript the value of a dropdown after and ajax made call has changed the iitem selected. – Cleptus Jul 06 '18 at 12:13
  • i just did save as https://stackoverflow.com/questions/22955839/how-to-fill-a-dropdown-using-jquery-ajax-call but from codebehind Selected text in empty string – Yogesh Singh Rawat Jul 06 '18 at 12:15
  • You have a drop down in your page, in Ajax call gets this control value and send to back end, in your action method you should add this parameter – mostafa Jul 06 '18 at 12:18
  • OK, you have retrieved the dropdown data via and ajax call and after data is retrieved you have populated the html control. Your question is not related with databindings or ajax, but with javascript/jquery. – Cleptus Jul 06 '18 at 12:19
  • Looks like you are using jquery. This question looks duplicated of [jQuery Get Selected Option From Dropdown](https://stackoverflow.com/questions/10659097/jquery-get-selected-option-from-dropdown) – Cleptus Jul 06 '18 at 12:22

1 Answers1

0

Show us your code for a better reply but I think you you can try

var value =yourDropDownList.SelectedValue 
F. Iván
  • 167
  • 1
  • 1
  • 12
  • I think his problem is not server side but client side (check the question comments). Because of that this answer is probably wrong. – Cleptus Jul 06 '18 at 12:42