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:
Hi...
can you please explain me how to bind hard coded country name in list in web service and then how to call that method in jquery,that method will be use for bind data into
dropdownlist???
Posted

1 solution

 
Share this answer
 
Comments
1989priya 5-Mar-14 13:07pm    
Hi Tadit...
Thanks for reply.
I want to bind hard coded country name in web service instead of retreive from database. I tried,but I am not getting how to do?
What is the exact problem? What have you tried? Can you show the code?
1989priya 6-Mar-14 10:54am    
Fisrt of all I made a web service..
public class WebService : System.Web.Services.WebService {

public WebService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}
public List<webservice> CountryInformation { get; set; }
[WebMethod]
public string LoadCountry()
{
string ab=null;
List<string> authors = new List<string>();

authors.Add("India");
authors.Add("US");
return authors;




}

}

then I am trying to call that web service in aspx page using jquery..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="jquery/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="jquery/jquery.validate.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$.ajax({
type:"POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/ LoadCountry",
data: "{}",
dataType: "json",
success: function (Result) {
$.each(Result.d, function (key, value) {
$("#DropDownList1").append($("<option></option>").val;

});
},
error: function (Result) {
alert("Error");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server">

</div>
</form>
</body>
</html>
Okay, so what is the issue with this code? Have you tested by debugging this code?
Do you see any errors in Developer Tool's Console?

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