Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
ajax webmethod is not working while dropdown bind


What I have tried:

<select class="filter_select" id="sr_picker" ">
</select>

<script type="text/javascript">
google.setOnLoadCallback(loadsr);

function loadsr() {
// alert();
$.ajax({
url: "/webmethod.aspx/Getsr",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(r) {
var ddlsection = $("[id*=sr_picker]");
//alert(ddlsection);
ddlsection.empty().append('<option selected="selected" value="0">All</option>');
$.each(r.d, function() {
ddlsection.append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('Got an Error ');
}
});
}
</script>





public static List<listitem> Getsr()
{
MasterLogic objMas = new MasterLogic();
// Utilities objUtl = new Utilities();

List<listitem> sectionname = new List<listitem>();
string qry = "select sales_person_code,sales_person_name from sales_personnel";
DataTable dt = objMas.GetDataTable(qry);

if (dt == null)
return sectionname;

List<datarow> list = dt.AsEnumerable().ToList();
for (int j = 0; j < dt.Rows.Count; j++)
{
sectionname.Add(new ListItem
{
Value = list[j].ItemArray[0].ToString(),
Text = list[j].ItemArray[1].ToString()
});

}

return sectionname;
}
Posted
Updated 23-Aug-16 6:16am
Comments
ZurdoDev 23-Aug-16 10:34am    
Why doesn't it work?

1 solution

Tested, Your code works fine, just Add WebMethod[^] attribute to the Method.
C#
[WebMethod]
public static List<ListItem> Getsr()
{
 
Share this answer
 
v2
Comments
Nethaji chennai 24-Aug-16 1:11am    
now also not work display got an error not call webmethod in breakpoint
Karthik_Mahalingam 24-Aug-16 1:13am    
what is the eror message
make sure the url is correct
url: "/webmethod.aspx/Getsr",
Nethaji chennai 24-Aug-16 2:28am    
problem solve url is wrong
Karthik_Mahalingam 24-Aug-16 2:33am    
ok , can you close this post.
Nethaji chennai 24-Aug-16 3:43am    
how

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900