Asp.net checkboxlist bound to datatextfield and datavaluefield in the background
The front-end page is found to be:
(1) the checkbox is separate, and there is no information in it. There is a label next to it that contains the text value.
<Input
Id = "dlwater_0" type = "checkbox"
Name = "dlwater $0"/> <label
For = "dlwater_0"> pH </label>
(2) No value found
There is no problem in obtaining the value and text value from the background, but considering the foreground acquisition, for example, selecting checkbox and displaying the selected value, remove the displayed value from the selected list and save the value (usually hidden by Den den) when selecting the value. Remove the value and text values when unselecting the value,
In this case, we need to get the text and value values from the foreground.
JS has not been considered, but jquery has tried
(1) jquery obtains the text value:
In Case 1, jquery implements
$ ("Input [type = 'checkbox']"). Click (function (){
VaR jcxmname = $ (this). Next (). Text (); // obtain the label value.
}
(2) jquery obtains the value:
From Case 2, we can see that after binding, the value is not displayed on the foreground (not clear), and there is no value on the foreground page, which jquery cannot obtain, therefore, you need to display the bound value. After finding out, you can use other methods to display the value to the foreground.
Foreach (listitem item in checkboxlist1.items)
{
Item. Attributes. Add ("Val", item. value );
}
After the value is bound, bind the value at the same time, so that the value is displayed on the foreground after the binding. (The value will be lost when the page is refreshed. What should I do, you know !)
The front-end code is as follows:
<Span
Val = "1001"> <Input
Id = "dlwater_0"
Type = "checkbox" name = "dlwater $0"/> <label
For = "dlwater_0"> pH </label> </span>
Discover multiple spans on the outermost side and display the value in the form of Val. This makes it easier.
I checked the information and found that jquery can take this value.
$ ("Input [type = 'checkbox']"). Click (function (){
VaR lvalue = $ (this). Parent ('span '). ATTR ("Val"); // obtain the value
VaR lname = $ (this). Next (). Text (); // get the text value
}
In this way, the value can be obtained in the foreground.