Hi my c# method is this:
[WebMethod]
protected static void fillList(HiddenField hiddenControl, System.Web.UI.WebControls.DropDownList listinc)
{
int dato = 0;
string strSql;
dato = Convert.ToInt32(hiddenControl.Value);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString());
conn.Open();
strSql = "SELECT DISTINCT incid FROM HisReportes WHERE peri = " + dato;
SqlCommand camAND = new SqlCommand(strSql, conn);
System.Data.DataTable tablainc = new System.Data.DataTable();
camAND.CommandTimeout = 36000;
tablainc.Load(camAND.ExecuteReader());
foreach (DataRow dtrw in tablainc.Rows)
{
listinc.Items.Add(dtrw[0].ToString());
}
}
i tested with a onlick function and it works but i need to call it from Ajax function:
$.ajax({
type: "POST",
url: "Incio.aspx/fillList",
data: '{hiddenControl , listinc, dtrw }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data)
{
$.each(data, function (){
$("listinc").append($("<option />").val(this.incidente).text(this.dtrw[0]));
});
},
failure: function () {
alert("Failed!");
}
});
that's my ajax function but it is not filling the dropdown list.
alertgo off?fillListmethod takes 2 parameters but your ajax sends just one parameter and its not even match. Second your code open to SQL injections. I think you need to know how Client/Server side communicate. You can check How to fill a DropDown using Jquery Ajax Call?