I am using a [webmethod] to retrieve a list of strings from sql-server. the code is :
[WebMethod]
public void SelectActivityCheckboxItems(int SystemID)
{
//Configure a connection to SystemRegister database
var cs = ConfigurationManager.ConnectionStrings["SYSTEMREGISTERConnectionString"].ConnectionString;
List<string> SelectedActivity = new List<string>();
//Get the related data for update activty checkbox
using (var con = new SqlConnection(cs))
{
con.Open();
var cmd = new SqlCommand("setModalSystemUpdate", con) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.AddWithValue("@SYSTEMID", SystemID);
var dr = cmd.ExecuteReader();
while (dr.Read())
{
SelectedActivity.Add(dr[0].ToString());
}
con.Close();
}
var js = new JavaScriptSerializer();
Context.Response.Write(js.Serialize(SelectedActivity));
}
Here is the checkboxlist:
<div class="scroll">
<fieldset class="form-group">
<label class="col-sm-3">Aktivitet:</label>
<div>
<asp:CheckBoxList CssClass="paddingright" ID="CheckBoxListActivityUpdate" runat="server"
DataSourceID="SqlDataSource6"
DataValueField="ACTIVITYNAME"
RepeatColumns="2">
</asp:CheckBoxList>
</div>
</fieldset>
</div>
In my aspx I have this Jquery to "check" the items that are in the list and exist in the checkboxlist.
$.ajax({
type: "POST",
url: "SystemService.asmx/SelectActivityCheckboxItems",
dataType: "json",
data: '{Value: "' + $("#<%=rowID.ClientID%>").value + '" }',
contentType: "application/json",
success: function (data) {
$.each(function () {
$("#CheckBoxListActivityUpdate").prop('checked', true);
})
}
});
unfortunatly this does not work, is there any other solutions?