Jquery sets the selected asp: CheckBoxList value based on the value returned by the interface, jquerycheckboxlist
Interface returns a json value, and then selects the corresponding value of asp: CheckBoxList through jquery
<Asp: CheckBoxList runat = "server" RepeatColumns = "4" ID = "cklistLMLX"> <asp: ListItem Text = "" Value = ""> </asp: listItem> <asp: ListItem Text = "cement" Value = "cement"> </asp: ListItem> <asp: listItem Text = "" Value = ""> </asp: ListItem> <asp: ListItem Text = "green" Value = "green"> </asp: listItem> <asp: ListItem Text = "Fast Lane" Value = "Fast Lane"> </asp: ListItem> <asp: listItem Text = "slow lane" Value = "slow lane"> </asp: ListItem> <asp: ListItem Text = "sidewalk" Value = "sidewalk"> </asp: listItem> <asp: ListItem Text = "" Value = ""> </asp: ListItem> </asp: CheckBoxList>
The code displayed in the browser is as follows:
<Table id = "cklistLMLX" border = "0"> <tbody> <tr> <td> <input id = "cklistLMLX_0" type = "checkbox" name = "cklistLMLX $0 "checked =" checked "> <label for =" cklistLMLX_0 "> tar </label> </td> <input id =" cklistLMLX_2 "type =" checkbox "name = "cklistLMLX $2"> <label for = "cklistLMLX_2"> channels </label> </td> <input id = "cklistLMLX_4" type = "checkbox" name = "cklistLMLX $4"> <label for = "cklistLMLX_4"> Fast Lane </label> </td> </tr> </tbody> </ table>
The returned lmlx data is as follows: Cell Road, sidewalk
Function SetCheckboxList (lmlx) {$ ("# cklistLMLX"). find ("input [type = checkbox]"). each (function (I ){
// Alert ($ (this ). val (); this method is incorrect // alert ($ (this ). next (). text (); if (lmlx. indexOf ($ (this ). next (). text ()> = 0) {$ (this ). attr ("checked", 'true');} else {$ (this ). removeAttr ("checked ");}});}
How does jquery obtain the value selected in the aspnet control CheckBoxList?
If you give the CheckBoxList an ID value
$ ("# Checkall: checked"). each (function (){
$ (This). val ();
});
Net how to set the default selected items for checkboxlist based on the database values
CheXgSfgl. SelectedValue = "2 ";