The CheckBoxList control on the ASP. NET Server side does not generate the value on the client side, so it is very troublesome to obtain the selected item through JS on the client side.
Forced to do so, you can only write the following code. This method is applicable to the control CheckBoxList. The RepeatLayout attribute is Flow and Table, and the RepeatDirection attribute is Horizontal and Vertical.
The objID is the ID generated by the ASP. NET Server Control on the client.
The general version does not depend on any class library)
- Function GetCheckBoxListValue (objID)
- {
- VarV=NewArray ();
- VarCheckBoxList=Document. GetElementById (objID );
- If (CheckBoxList. tagName= "TABLE ")
- {
- For (I=0; I<CheckBoxList. rows. length; I ++)
- For (J=0; J<CheckBoxList. rows[I]. cells. length; j ++)
- If (CheckBoxList. rows [I]. cells [j]. childNodes [0])
- If (CheckBoxList. rows [I]. cells [j]. childNodes [0]. Checked= True)
- V. push (CheckBoxList. rows [I]. cells [j]. childNodes [1]. innerText );
- }
- If (CheckBoxList. tagName= "SPAN ")
- {
- For (I=0; I<CheckBoxList. childNodes. length; I ++)
- If (CheckBoxList. childNodes [I]. TagName= "INPUT ")
- If (CheckBoxList. childNodes [I]. Checked= True)
- {
- I ++;
- V. push (CheckBoxList. childNodes [I]. innerText );
- }
- }
- Return v;
- }
- The Asp.net Ajax version depends on the support of the Asp.net Ajax class library)
- Function GetCheckBoxListValue (objID)
- {
- VarV=NewArray ();
- VarCheckBoxList= $ Get (objID );
- If (CheckBoxList. tagName= "TABLE ")
- {
- For (I=0; I<CheckBoxList. rows. length; I ++)
- For (J=0; J<CheckBoxList. rows[I]. cells. length; j ++)
- If (CheckBoxList. rows [I]. cells [j]. childNodes [0])
- If (CheckBoxList. rows [I]. cells [j]. childNodes [0]. Checked= True)
- Array. add (v, CheckBoxList. rows [I]. cells [j]. childNodes [1]. innerText );
- }
- If (CheckBoxList. tagName= "SPAN ")
- {
- For (I=0; I<CheckBoxList. childNodes. length; I ++)
- If (CheckBoxList. childNodes [I]. TagName= "INPUT ")
- If (CheckBoxList. childNodes [I]. Checked= True)
- {
- I ++;
- Array. add (v, CheckBoxList. childNodes [I]. innerText );
- }
- }
- Return v;
- }
The preceding section describes the ASP. NET Server Control CheckBoxList.
- ASP. NET TypeConverter
- Analysis on TypeResolver of ASP. NET
- Define JavaScriptConverter in ASP. NET
- How to replace Sys. Services in ASP. NET
- Use Profile Service of ASP. NET AJAX