This way
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$(function () {
$.ajax({
type: "POST",
url: "CS.aspx/GetCustomers",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
});
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Table");
var row = $("[id*=CheckBoxList1] tr:last-child").clone(true);
$("[id*=CheckBoxList1] tr").remove();
$.each(customers, function () {
var customer = $(this);
$("input", row).val($(this).find("CustomerID").text());
$("label", row).html($(this).find("ContactName").text());
$("[id*=CheckBoxList1] tbody").append(row);
row = $("[id*=CheckBoxList1] tr:last-child").clone(true);
});
}
</script>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="test" Value="0"></asp:ListItem>
</asp:CheckBoxList>
[WebMethod]
public static string GetCustomers()
{
string query = "SELECT top 10 CustomerID, ContactName, City FROM Customers";
SqlCommand cmd = new SqlCommand(query);
return GetData(cmd).GetXml();
}
private static DataSet GetData(SqlCommand cmd)
{
string strConnString = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}