title: JQuery return an array of drop down list items from asmx web service and then bind to drop down list?
body: <p>All,</p>
  
  <p>How can I bind the array of drop down list items returned from the web service method to the ddlSubCategory asp.net server control? Here is my code. See comments in the jquery OnSuccess method:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $('#&lt;%=ddlParentCategory.ClientID%&gt;').change(function () {
              var selectedParentCategory = getParentCategorySelectedValue();
  var params=  []; 
  params[id] = selectedParentCategory;  
  
            $.ajax({
                                type: "POST",
                                url: "MyWebService.asmx/GetSubCategoryItems",
                                data: params,               
                                contentType: "application/json; charset=utf-8",               
                                dataType: "json",               
                                success: OnSuccess,               
                                error: OnError
             });
                        });
  
      function OnSuccess(data, status) {
  ;// need to populate ddlSubCategory &lt;asp:DropDownList on UI now
  ;// using returned array of drop down list items from the web service
      }        
  
      function OnError(request, status, error) {
                     alert(request.statusText);
      }
  
          function getParentCategorySelectedValue() {
              var SelectedVal = $('#&lt;%=ddlParentCategory.ClientID %&gt;').val();
              return SelectedVal;
          }
  
     });    
  &lt;/script&gt;
  
  Here is my web service web method returning the array of list items:
  
  [WebMethod]
          public ListItem []  GetSubCategoryItems(int id)
          {
              using (var dc = MyDataContext.Open())
              {
                  return dc.SubCategory
                      .OrderBy(sc =&gt; sc.Name)
                      .Select(sc =&gt; new ListItem()
                                       {
                                           Value = sc.ID.ToString(),
                                           Text = sc.Name
                                       })
                      .Prepend(new ListItem() {Value = "", Text = "Please Select"})
                      .ToArray();
              }
          }
  </code></pre>
  
  <p>thanks for any help!</p>