Add checkboxes into checkboxlist.
For eg: I am passing dataset value as "1001","1002","1003","1004","1005" and get this value as XML using GetXml() function.
The above value, will for 5 checkboxes separately and add into checkbox list.
Default.apsx.vb
<WebMethod()> _
Public Shared Function returnData() As String
Dim dsUtil As New DataSet
Dim lstSQL As String
Dim fdat, tdat, detai, valG, sta As String
Try
fdat = "20140317"
tdat = "20140318"
detai = "College"
valG = "Y"
sta = "2"
lstrSQL = ("Exec SP_College '" & fdat & "','" & tdat & "','" & detai & "','" & valG & "','" & sta & "'")
_Command = New SqlCommand(lstSQL)
Return GetDataset(_Command).GetXml()
Catch Ex As Exception
Throw New Exception("Error " & Ex.Message)
End Try
'Return ms
End Function
Public Shared Function GetDataset(ByVal tSQLQuery As SqlCommand) As DataSet
Dim ds As New DataSet
cn = New SqlConnection("Data Source=localhost; Initial Catalog = master;uid=sa;pwd=sa;")
Try
cn.Open()
Dim da As New SqlDataAdapter(_Command)
_Command.CommandType = CommandType.Text
_Command.Connection = cn
da.Fill(ds, "UTable")
Return ds
Catch oEx As Exception
Throw New Exception("GetDataset-" & oEx.Message)
Finally
ds.Dispose()
End Try
End Function
**Default.aspx page**
<table>
<tr>
<td>
<input type="button" id="btnTray" value="Click here" onclick="checnkAjaxfn()"/>
</td>
<td>
<div id="divCheckBoxList" >
<asp:CheckBoxList ID="chklistId" runat="server">
</asp:CheckBoxList>
</div>
</td>
</tr>
</table>
**Ajax. Json script:**
function checnkAjaxfn() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Default.aspx/returnData",
data:{},
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
debugger;
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var xmlData = xml.find("UTable");
var row = $("[id*=chklistId] tr:last-child").clone(true);
$("[id*=chklistId] tr").remove();
$.each(xmlData , function () {
var xData = $(this);
$("label", row).val($(this).find("Sys_ID").text());
$("[id*=chklistId] tbody").append(row);
row = $("[id*=chklistId] tr:last-child").clone(true);
});
}
The above does not add checkbox to checkboxlist.
I debugged. when it reach
$.each(xmlData , function () {
this line, its come at end line.
pls say how to generate checkbox inside checkboxlist