Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to play with List of List of String with Javascript or Jquery using Ajax?
    text
    copied!<p>We're working on a big ASP.NET\VB.NET website project. I need to populate three dropdownlists. To last two are independent of the previous ones. The population data comes from an SQL Server. I'd have no problem doing this with code-behind with post back but we don't want any PostBacks so I started to develop this in Ajax\jQuery.</p> <p>Preface:</p> <p>The dropdownlist's values and text are both different and tied up to the database. Server-side, the function called by the Ajax method returns a list of list of string with the values and text, i.e. </p> <pre><code>list[0][0] = "ID0" list[0][1] = "VP" </code></pre> <p>The list is well built and returns the right value taken from the database.</p> <p>Problem:</p> <p>Now I want to populate the dropdownlist from the list sent to the ajax success response and I have a hard time doing it.</p> <p>Here's the ajax part of it so far </p> <pre><code>$.ajax( { type: "POST", url: "Projet.aspx/GetDir", data: "{VP:'" + dd_effort_vp + "',DP:'" + dd_effort_dp + "',Direction:'" + dd_effort_d + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(response) { // This code works if only a simple list of string is // returned from the server-side called function. var cars = response.d; $.each(cars, function(index, value) { $('#&lt;%= dd_effort_directionp.clientid()%&gt;').append( $('&lt;option&gt;&lt;/option&gt;').val(value).html(value)); }); } </code></pre> <p>This code works IF and only IF I have a simple list of string returned by the server side function. </p> <p>Now I want to modify it to get the values from the List of List of String (in <code>var cars</code> and assign the right ID and Description to each item in the newly populated DropdownList.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload