Tengo un dropdown list de ASP.Net, intento llenarlo desde una llamada Ajax, entra el método de ASP.net, y en C# retorno la lista con la cual se llenará, pero cuando termino de debuggear el método, el dropdownlist sigue sin datos. Éste es mi código
[WebMethod]
public static List<Lista> ListadoUsuariosAjax()
{
try
{
///
List<Lista> lstNombreLista = new List<Lista>();
XmlSerializer xml_serializer = new XmlSerializer(typeof(cLogin));
StringReader string_reader = new StringReader(CookieUtils.LeeValorCookie(System.Web.Configuration.WebConfigurationManager.AppSettings["nombreCookie"]));
cLogin myLogin = (cLogin)xml_serializer.Deserialize(string_reader);
///
DataTable dt = new DataTable();
#region Cadena de Conexión
SqlConnection miConexion = new SqlConnection(cadenaCon);
#endregion
if (miConexion.State == ConnectionState.Closed)
{
miConexion.Open();
}
using (SqlCommand comando = new SqlCommand("select Distinct NombreLista from ListaDestinatarios", miConexion))
{
SqlDataAdapter da = new SqlDataAdapter(comando);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
lstNombreLista.Add(
new Lista
{
NombreLista = dt.Rows[i]["NombreLista"].ToString(),
NombreListaID = dt.Rows[i]["NombreLista"].ToString()
});
}
}
return lstNombreLista;
}
}
catch (Exception ex)
{
return null;
}
}
Ajax Call
function GetDropDownData() {
$.ajax({
type: "POST",
url: "Formularios.aspx/ListadoUsuariosAjax",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$('#ddlUsers').empty();
$('#ddlUsers').append("<option value='0'>--Selecciona Lista--</option>");
$.each(result.d, function (key, value) {
debugger
$('#ddlUsers').append($("<option></option>").val(value.NombreLista).html(value.NombreListaID));
});
},
failure: function () {
alert("Failed!");
}
});
}
DDList
<div>
<asp:DropDownList ID="ddlUsers" runat="server">
</asp:DropDownList>
</div>