Jquery sets the selected asp: CheckBoxList value based on the value returned by the interface, jquerycheckboxlist

Source: Internet
Author: User

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 ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.