how to handle dropdownlist mvc/jqueryhttp://forums.asp.net/t/1775565.aspx/1?how+to+handle+dropdownlist+mvc+jqueryThu, 01 Mar 2012 13:35:20 -050017755654858829http://forums.asp.net/p/1775565/4858829.aspx/1?how+to+handle+dropdownlist+mvc+jqueryhow to handle dropdownlist mvc/jquery <p>i´m new developing on asp.net mvc, and even newer using jquery, so this is my problem: i have a few dropdown list that are filled dinamically using the data of another dropdown or textbox, and the data of those drop down is used for another drop down, like a chain, my problem rigth now is that the dropdown sometimes just have one answer/option, and if i try to select that option jquery doesn´t activate the &#36;(&quot;#anything&quot;).change() event, 'cause i have just one option, how i handle it?</p> <p><a href="http://imageshack.us/photo/my-images/20/sinttulolp.jpg/" rel="nofollow">http://imageshack.us/photo/my-images/20/sinttulolp.jpg/</a></p> <p>for example this i need the data of the red circle for filling the blue circle, but the red circle just have one option and if i click nothing happens</p> <p>code:</p> <p></p> <pre class="prettyprint">$(&quot;#tbClave1&quot;).change(function() { if ($(&quot;#tbClave1&quot;).val().length == 4) { updateClave2($(&quot;#tbClave1&quot;).val()); } }); function updateClave2(cod) { var dd = document.getElementById(&quot;ddClave2&quot;); dd.options.length = 0; dd.options[0] = new Option(&quot;Espere...&quot;); dd.selectedIndex = 0; dd.disabled = true; codigo = cod; tipoArt = $(&quot;#ddTipoArticulo&quot;).val(); // Control de errores $(&quot;#ddClave2&quot;).ajaxError(function(event, request, settings) { dd.options[0] = new Option(&quot;No se Cargaron Datos&quot;); }); // Obtenemos los datos... $.ajax({ url: '/Home/GetClave2', dataType: 'json', data: { words: codigo, tipoArticulo: tipoArt }, success: function(data, textStatus, jqXHR) { $.each(data, function(i, item) { dd.options[i] = new Option(item[&quot;clave2&quot;], item[&quot;clave2&quot;]); }); dd.disabled = false; } }); } controller: public ActionResult GetClave2(string words, string tipoArticulo){ List&lt;Pedidos&gt; mySource = miConexion.Clave2(username, password, words, tipoArticulo); return Json(mySource); } connection: public List&lt;Pedidos&gt; Clave2(string username, string password, string clave1, string tipoArticulo) { List&lt;Pedidos&gt; clave2 = new List&lt;Pedidos&gt;(); try { OleDbConnection conexion = new OleDbConnection (@&quot;....&quot;); OleDbCommand comandoSelect = new OleDbCommand(@&quot; sql sentence &quot; , conexion); comandoSelect.Connection = conexion; conexion.Open(); comandoSelect.ExecuteNonQuery(); OleDbDataReader resultado = comandoSelect.ExecuteReader(); while (resultado.Read()){ Pedidos miClave2 = new Pedidos(); miClave2.clave2 = resultado.GetString(0); clave2.Add(miClave2); } conexion.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return clave2; }</pre> 2012-03-01T11:52:20-05:004858881http://forums.asp.net/p/1775565/4858881.aspx/1?Re+how+to+handle+dropdownlist+mvc+jqueryRe: how to handle dropdownlist mvc/jquery <p>check this cascading dropdown list</p> <p>http://www.c-sharpcorner.com/uploadfile/2124ae/cascading-dropdown-list-in-Asp-Net-mvc-2-using-jquery/</p> 2012-03-01T12:26:03-05:004859005http://forums.asp.net/p/1775565/4859005.aspx/1?Re+how+to+handle+dropdownlist+mvc+jqueryRe: how to handle dropdownlist mvc/jquery <p>but i&nbsp;initialize, and fill it different ... how i add that first value to the dropdown, and then start fill it in the next position?</p> <p>i forgot tell u that i use mvc v1</p> <pre class="prettyprint">How i initialize: ViewData[&quot;ddClave2&quot;] = new SelectList(new[] { &quot;(Selecciona)&quot; }); how i deffine it: &lt;% =Html.DropDownList(&quot;ddClave2&quot;) %&gt;</pre> 2012-03-01T13:35:20-05:00