ASP.NET服务器端控件CheckBoxList

开发 后端
本文介绍ASP.NET服务器端控件CheckBoxList在客户端没有生成value值,所以就想在客户端通过JS获得选中项就很麻烦了。

ASP.NET服务器端控件CheckBoxList在客户端没有生成value值,所以就想在客户端通过JS获得选中项就很麻烦了。
迫于无奈,只能写了以下的代码。比较通用,适合于控件CheckBoxList的属性RepeatLayout为Flow和Table,属性RepeatDirection为Horizontal和Vertical
objID为ASP.NET服务器端控件在客户端生成的ID

通用版本(不依赖任何类库)

 

  1. function GetCheckBoxListValue(objID)  
  2. {  
  3. var v = new Array();  
  4. var CheckBoxList = 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. Asp.net Ajax版本(依赖Asp.net Ajax类库支持)  
  26. function GetCheckBoxListValue(objID)  
  27. {  
  28. var v = new Array();  
  29. var CheckBoxList = $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;  


以上介绍ASP.NET服务器端控件CheckBoxList。

【编辑推荐】

  1. ASP.NET的TypeConverter
  2. 浅析ASP.NET的TypeResolver
  3. ASP.NET中定义JavaScriptConverter
  4. 在ASP.NET中替换Sys.Services的方法
  5. 使用ASP.NET AJAX的Profile Service
责任编辑:佚名 来源: IT168
相关推荐

2009-09-03 18:37:35

ASP.net

2011-07-06 13:41:06

ASP.NET

2009-08-04 13:10:05

ASP.NET服务器控

2009-08-10 14:25:33

ASP.NET服务器控

2009-08-10 14:08:15

ASP.NET服务器控ASP.NET组件设计

2009-08-03 18:00:00

ASP.NET服务器控

2009-08-04 17:18:37

2011-07-12 15:17:02

ASP.net服务器控件

2009-08-05 18:36:12

ASP.NET Che

2009-07-30 16:52:38

复合控件ASP.NET服务器控

2009-08-07 13:56:46

ASP.NET控件开发

2009-08-06 14:16:04

ASP.NET服务器控

2009-08-01 10:07:58

ASP.NET服务器控ASP.NET

2009-08-04 15:13:38

2009-08-04 13:39:43

ASP.NET 2.0

2009-08-03 15:43:22

asp.net控件

2009-08-10 15:42:33

ASP.NET Che

2011-07-12 15:03:28

2009-08-01 20:59:08

ASP.NET服务器控ASP.NET服务器ASP.NET

2009-08-06 14:42:54

ASP.NET服务器控
点赞
收藏

51CTO技术栈公众号