<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" language="javascript">
$(function() {
$.ajax({
type: 'POST',
url: '/Webservice/MyService/FillDropDown',
cache: false,
async:false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(data) {
$('#ddslick').html(data.d);
}
});
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="ddslick"></select>
</div>
</form>
</body>
</html>
Now the Webservice.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyService : System.Web.Services.WebService {
[WebMethod]
public string FillDropDown()
{
string _str = string.Empty;
MyClass obj = new MyClass();
_str= obj.FillDropDown();
return _str;
}
}
Now, the class code called...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
public class MyClass
{
string con = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string _str = string.Empty;
public string FillDropDown()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (SqlConnection conn = new SqlConnection(con))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "proc_GetddlData";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
try
{
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
sb.Append("<option>" + dr[0] + "</option>");
}
_str = sb.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
return _str;
}
}
Into the SP ,you only need to get the dropdown values .....
Try and Run, hope your problem will be solved.