Here I have created sample that will help you out.
You need to set async to false.Please refer below article
HTML
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
LoadCity();
LoadLocalCity();
});
function LoadCity() {
$.ajax({
type: "POST",
url: "Default.aspx/GetCategory",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
function OnSuccess(r) {
var categorys = r.d;
var repeatColumns = parseInt("<%=chkItems.RepeatColumns%>");
if (repeatColumns == 0) {
repeatColumns = 1;
}
var cell = $("[id*=chkItems] td").eq(0).clone(true);
$("[id*=chkItems] tr").remove();
$.each(categorys, function (i) {
var row;
if (i % repeatColumns == 0) {
row = $("<tr />");
$("[id*=chkItems] tbody").append(row);
} else {
row = $("[id*=chkItems] tr:last-child");
}
var checkbox = $("input[type=checkbox]", cell);
//Set Unique Id to each CheckBox.
checkbox[0].id = checkbox[0].id.replace("0", i);
//Give common name to each CheckBox.
checkbox[0].name = "CityId";
//Set the CheckBox value.
checkbox.val(this.Value);
var label = cell.find("label");
if (label.length == 0) {
label = $("<label />");
}
//Set the 'for' attribute of Label.
label.attr("for", checkbox[0].id);
//Set the text in Label.
label.html(this.Text);
//Append the Label to the cell.
cell.append(label);
//Append the cell to the Table Row.
row.append(cell);
cell = $("[id*=chkItems] td").eq(0).clone(true);
});
$("[id*=chkItems] input[type=checkbox]").click(function () {
var cell = $(this).parent();
var hidden = cell.find("input[type=hidden]");
var label = cell.find("label");
if ($(this).is(":checked")) {
//Add Hidden field if not present.
if (hidden.length == 0) {
hidden = $("<input type = 'hidden' />");
cell.append(hidden);
}
hidden[0].name = "CityName";
//Set the Hidden Field value.
hidden.val(label.text());
cell.append(hidden);
} else {
cell.remove(hidden);
}
});
};
}
function LoadLocalCity() {
$.ajax({
type: "POST",
url: "Default.aspx/GetCitylocation",
data: '{}',
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
function OnSuccess(r) {
var locations = r.d;
var repeatColumns = parseInt("<%=Chklocal.RepeatColumns%>");
if (repeatColumns == 0) {
repeatColumns = 1;
}
var cell = $("[id*=Chklocal] td").eq(0).clone(true);
$("[id*=Chklocal] tr").remove();
$.each(locations, function (i) {
var row;
if (i % repeatColumns == 0) {
row = $("<tr />");
$("[id*=Chklocal] tbody").append(row);
} else {
row = $("[id*=Chklocal] tr:last-child");
}
var checkbox = $("input[type=checkbox]", cell);
//Set Unique Id to each CheckBox.
checkbox[0].id = checkbox[0].id.replace("0", i);
//Give common name to each CheckBox.
checkbox[0].name = "localid";
//Set the CheckBox value.
checkbox.val(this.Value);
var label = cell.find("label");
if (label.length == 0) {
label = $("<label />");
}
//Set the 'for' attribute of Label.
label.attr("for", checkbox[0].id);
//Set the text in Label.
label.html(this.Text);
//Append the Label to the cell.
cell.append(label);
//Append the cell to the Table Row.
row.append(cell);
cell = $("[id*=Chklocal] td").eq(0).clone(true);
});
$("[id*=Chklocal] input[type=checkbox]").click(function () {
var cell = $(this).parent();
var hidden = cell.find("input[type=hidden]");
var label = cell.find("label");
if ($(this).is(":checked")) {
//Add Hidden field if not present.
if (hidden.length == 0) {
hidden = $("<input type = 'hidden' />");
cell.append(hidden);
}
hidden[0].name = "localcity";
//Set the Hidden Field value.
hidden.val(label.text());
cell.append(hidden);
} else {
cell.remove(hidden);
}
});
};
}
</script>
<asp:CheckBoxList ID="chkItems" runat="server" RepeatColumns="1">
<asp:ListItem Text="" Value=""></asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:CheckBoxList ID="Chklocal" runat="server" RepeatColumns="1">
<asp:ListItem Text="" Value=""></asp:ListItem>
</asp:CheckBoxList>
</div>
C#
[WebMethod]
public static List<ListItem> GetCategory()
{
DataTable dt = new DataTable();
dt.Columns.Add("CityId");
dt.Columns.Add("CityName");
dt.Rows.Add(1, "Mumbai");
dt.Rows.Add(2, "Thane");
List<ListItem> categorys = new List<ListItem>();
foreach (DataRow dr in dt.Rows)
{
categorys.Add(new ListItem
{
Text = dr["CityName"].ToString(),
Value = dr["CityId"].ToString()
});
}
return categorys;
}
[WebMethod]
public static List<ListItem> GetCitylocation()
{
List<ListItem> locations = new List<ListItem>();
DataTable dt = new DataTable();
dt.Columns.Add("localid");
dt.Columns.Add("localcity");
dt.Rows.Add(1, "Sub-Mumbai");
dt.Rows.Add(2, "Sub-Thane");
foreach (DataRow dr in dt.Rows)
{
locations.Add(new ListItem
{
Text = dr["localcity"].ToString(),
Value = dr["localid"].ToString()
});
}
return locations;
}
Screenshot
