ASP. NET Server-side control CheckBoxList

Source: Internet
Author: User

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)

 
 
  1. Function GetCheckBoxListValue (objID)
  2. {
  3. VarV=NewArray ();
  4. VarCheckBoxList=Document. GetElementById (objID );
  5. If (CheckBoxList. tagName= "TABLE ")
  6. {
  7. For (I=0; I<CheckBoxList. rows. length; I ++)
  8. For (J=0; J<CheckBoxList. rows[I]. cells. length; j ++)
  9. If (CheckBoxList. rows [I]. cells [j]. childNodes [0])
  10. If (CheckBoxList. rows [I]. cells [j]. childNodes [0]. Checked= True)
  11. V. push (CheckBoxList. rows [I]. cells [j]. childNodes [1]. innerText );
  12. }
  13. If (CheckBoxList. tagName= "SPAN ")
  14. {
  15. For (I=0; I<CheckBoxList. childNodes. length; I ++)
  16. If (CheckBoxList. childNodes [I]. TagName= "INPUT ")
  17. If (CheckBoxList. childNodes [I]. Checked= True)
  18. {
  19. I ++;
  20. V. push (CheckBoxList. childNodes [I]. innerText );
  21. }
  22. }
  23. Return v;
  24. }
  25. The Asp.net Ajax version depends on the support of the Asp.net Ajax class library)
  26. Function GetCheckBoxListValue (objID)
  27. {
  28. VarV=NewArray ();
  29. VarCheckBoxList= $ Get (objID );
  30. If (CheckBoxList. tagName= "TABLE ")
  31. {
  32. For (I=0; I<CheckBoxList. rows. length; I ++)
  33. For (J=0; J<CheckBoxList. rows[I]. cells. length; j ++)
  34. If (CheckBoxList. rows [I]. cells [j]. childNodes [0])
  35. If (CheckBoxList. rows [I]. cells [j]. childNodes [0]. Checked= True)
  36. Array. add (v, CheckBoxList. rows [I]. cells [j]. childNodes [1]. innerText );
  37. }
  38. If (CheckBoxList. tagName= "SPAN ")
  39. {
  40. For (I=0; I<CheckBoxList. childNodes. length; I ++)
  41. If (CheckBoxList. childNodes [I]. TagName= "INPUT ")
  42. If (CheckBoxList. childNodes [I]. Checked= True)
  43. {
  44. I ++;
  45. Array. add (v, CheckBoxList. childNodes [I]. innerText );
  46. }
  47. }
  48. Return v;
  49. }


The preceding section describes the ASP. NET Server Control CheckBoxList.

  1. ASP. NET TypeConverter
  2. Analysis on TypeResolver of ASP. NET
  3. Define JavaScriptConverter in ASP. NET
  4. How to replace Sys. Services in ASP. NET
  5. Use Profile Service of ASP. NET AJAX

Related Article

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.