ASP.NET CheckBoxList组件中经常使用到的属性:

I .TextAlign属性:取值为:Left、Right。如果TextAlign的值为Left则CheckBoxList组件中的检查框的文字在选框的左边,同理如果TextAlign的值为Right则检查框的文字在选框的右边。

II .Selected属性:为布尔型,判定组件中的检查框是否被选中。

III .RepeatColumns属性:在CheckBoxList组件中有若干检查框,此属性主要是设定这些检查框到底用多少行来显示。

IV .RepeatDirection属性:此属性的值可为:Vertical、Horizontal。当设定了RepeatColumns属性后,设定此属性是如何排列组件中的各个检查框的。具体如下:

假定CheckBoxList组件有四个检查框,并且RepeatColumns属性值为2。

(1).如果RepeatDirection = Vertical,则在页面中检查框的显示方式如下:

检查框01 检查框03

检查框02 检查框04

(2).如果RepeatDirection = Horizontal,则在页面中检查框的显示方式如下:

检查框01 检查框02

检查框03 检查框04

V .Count属性:返回CheckBoxList组件中有多少检查框。

三. ASP.NET CheckBoxList组件编程中经常使用到的方法:

(1).在组件中增加一个检查框,语法如下:

  1. CHKList . Items . Add ( new ListItem ( ﹤ text ﹥ , ﹤ value ﹥ ) )

(2).访问组件中的检查框,语法如下:

  1. CHKList . Items [ ﹤ index ﹥ ]

(3).删除组件中的检查框,语法如下:

  1. CHKList . Items . Remove ( ﹤ index ﹥ )

四. 实例介绍ASP.NET CheckBoxList组件的使用方法:

(1).如何判定选择了组件中的哪些检查框:

在程序中,是通过处理Selected属性和Count属性来完成的,具体如下:

  1. for ( int i = 0 ; i ﹤ ChkList . Items . Count ; i++ )
  2. {
  3. if( ChkList . Items [ i ] . Selected )
  4. {
  5. lblResult . Text += ChkList . Items [ i ] .Text + "  " ;
  6. }
  7. }

(2).如何设定ASP.NET CheckBoxList组件的外观布局:

CheckBoxList组件有比较多的属性来设定它的外观,在本文介绍的程序中,主要是通过四个方面来设定组件的外观布局的:组件中的检查框中的文本和选框的排列位置、组件中各个检查框布局、

组件中各个检查框排列方向和组件中各个检查框的排列行数,具体的程序代码如下:

  1. //组件中的检查框中的文本和选框的排列位置
  2. switch ( cboAlign . SelectedIndex )
  3. {
  4.  case 0 :
  5. ChkList . TextAlign = TextAlign . Left ;
  6. break ;
  7.  case 1 :
  8. ChkList . TextAlign = TextAlign . Right ;
  9. break ;
  10. }
  11. //组件中各个检查框布局
  12. switch ( cboRepeatLayout . SelectedIndex )
  13. {
  14.  case 0 :
  15. ChkList . RepeatLayout = RepeatLayout . Table ;
  16. break ;
  17.  case 1 :
  18. ChkList . RepeatLayout = RepeatLayout . Flow ;
  19. break ;
  20. }
  21. //组件中各个检查框排列方向
  22. switch ( cboRepeatDirection . SelectedIndex)
  23. {
  24.  case 0 :
  25. ChkList . RepeatDirection = RepeatDirection . Vertical ;
  26. break ;
  27.  case 1 :
  28. ChkList . RepeatDirection = RepeatDirection . Horizontal ;
  29. break ;
  30. }
  31. //组件中各个检查框的排列行数
  32. try
  33. {
  34.  int cols = int . Parse ( txtRepeatCols.Text ) ;
  35.  ChkList . RepeatColumns = cols ;
  36. }
  37. catch ( Exception )
  38. {
  39. }

五. 文中源程序代码(Check.aspx):

Check.aspx源程序代码如下:

  1. ﹤% @ Page Language = "C#" %﹥
  2. ﹤html ﹥
  3. ﹤head ﹥
  4. ﹤title ﹥ CheckBoxList组件演示程序 ﹤/title ﹥
  5. ﹤script runat = "server" ﹥
  6.  protected void Button_Click ( object sender , EventArgs e )
  7.  {
  8. //组件中的检查框中的文本和选框的排列位置
  9. switch ( cboAlign . SelectedIndex )
  10. {
  11.  case 0 :
  12. ChkList . TextAlign = TextAlign . Left ;
  13. break ;
  14.  case 1 :
  15. ChkList . TextAlign = TextAlign . Right ;
  16. break ;
  17. }
  18. //组件中各个检查框布局
  19. switch ( cboRepeatLayout . SelectedIndex )
  20. {
  21.  case 0 :
  22. ChkList . RepeatLayout = RepeatLayout . Table ;
  23. break ;
  24.  case 1 :
  25. ChkList . RepeatLayout = RepeatLayout . Flow ;
  26. break ;
  27. }
  28. //组件中各个检查框排列方向
  29. switch ( cboRepeatDirection . SelectedIndex)
  30. {
  31.  case 0 :
  32. ChkList . RepeatDirection = RepeatDirection . Vertical ;
  33. break ;
  34.  case 1 :
  35. ChkList . RepeatDirection = RepeatDirection . Horizontal ;
  36. break ;
  37. }
  38. //组件中各个检查框的排列行数
  39. try
  40. {
  41.  int cols = int . Parse ( txtRepeatCols.Text ) ;
  42.  ChkList . RepeatColumns = cols ;
  43. }
  44. catch ( Exception )
  45. {
  46. }
  47. lblResult . Text = "" ;
  48. for ( int i = 0 ; i ﹤ ChkList . Items . Count ; i++ )
  49. {
  50.  if( ChkList . Items [ i ] . Selected )
  51.  {
  52. lblResult . Text += ChkList . Items [ i ] .Text + "  " ;
  53.  }
  54. }
  55.  }
  56.  ﹤/script ﹥
  57.  ﹤/head ﹥
  58.  ﹤body ﹥
  59.  ﹤form runat = "server" ﹥
  60. ﹤h1 align = center ﹥ CheckBoxList组件演示程序 ﹤/h1 ﹥
  61. ﹤table ﹥
  62.  ﹤tr ﹥
  63. ﹤td ﹥ 组件中的文本排列位置: ﹤/td ﹥
  64. ﹤td ﹥
  65. ﹤asp:DropDownList id = cboAlign runat = "server" ﹥
  66.  ﹤asp:ListItem ﹥ 居左 ﹤/asp:ListItem ﹥
  67.  ﹤asp:ListItem ﹥ 居右 ﹤/asp:ListItem ﹥
  68. ﹤/asp:DropDownList ﹥
  69. ﹤/td ﹥
  70.  ﹤/tr ﹥
  71.  ﹤tr ﹥
  72. ﹤td ﹥ 组件中各个条目布局: ﹤/td ﹥
  73. ﹤td ﹥
  74. ﹤asp:DropDownList id = cboRepeatLayout runat = "server" ﹥
  75.  ﹤asp:ListItem ﹥ 表格型 ﹤/asp:ListItem ﹥
  76.  ﹤asp:ListItem ﹥ 紧凑型 ﹤/asp:ListItem ﹥
  77. ﹤/asp:DropDownList ﹥
  78. ﹤/td ﹥
  79.  ﹤/tr ﹥
  80.  ﹤tr ﹥
  81. ﹤td﹥ 组件中各个条目排列方向:﹤/td ﹥
  82. ﹤td ﹥
  83. ﹤asp:DropDownList id = cboRepeatDirection runat = "server" ﹥
  84.  ﹤asp:ListItem ﹥ 水平方向 ﹤/asp:ListItem ﹥
  85.  ﹤asp:ListItem ﹥ 垂直方向 ﹤/asp:ListItem ﹥
  86. ﹤/asp:DropDownList ﹥
  87. ﹤/td ﹥
  88.  ﹤/tr ﹥
  89.  ﹤tr ﹥
  90. ﹤td ﹥ 组件中各个条目排列行数: ﹤/td ﹥
  91. ﹤td ﹥ ﹤asp:TextBox id = "txtRepeatCols" runat = "server" /﹥ ﹤/td ﹥
  92.  ﹤/tr ﹥
  93. ﹤/table ﹥

请选择你所需要学习的计算机语言类型:

  1. ﹤asp:CheckBoxList id = "ChkList" RepeatDirection = Horizontal runat = "server" ﹥
  2.  ﹤asp:ListItem ﹥ Visual C++ .Net ﹤/asp:ListItem ﹥
  3.  ﹤asp:ListItem ﹥ Visual C# ﹤/asp:ListItem ﹥
  4.  ﹤asp:ListItem ﹥ VB.NET ﹤/asp:ListItem ﹥
  5.  ﹤asp:ListItem ﹥ JScript.NET ﹤/asp:ListItem ﹥
  6.  ﹤asp:ListItem ﹥ Visual J# ﹤/asp:ListItem ﹥
  7. ﹤/asp:CheckBoxList ﹥
  8.  ﹤asp:Button Text = "提交" runat = "server" onclick = "Button_Click" /﹥
  9.  ﹤h1 ﹥ ﹤font color = red ﹥ 你选择的计算机语言类型为: ﹤/font ﹥ ﹤/h1 ﹥
  10.  ﹤asp:Label id = lblResult runat = "server" /﹥
  11.  ﹤/form ﹥
  12.  ﹤/body ﹥
  13. ﹤/html ﹥

[.NET]CheckBoxList 用法相关推荐

  1. checkboxlist详细用法、checkboxlist用法、checkboxlist

    for (int i = 0; i < CheckBoxList1.Items.Count; i++) {       if (CheckBoxList1.Items[i].Selected) ...

  2. Struts2学习笔记(三)

    一.Struts2国际化   Struts2可以为JSP页面.Action.全局范围分别提供不同的国际化资源,这样维护系统时可以分开维护JSP页面.Action的国际化资源,从而提供更好的可维护性.S ...

  3. CheckBoxList详细用法

    1.绑定数据 this.lngCatalogID.DataSource = dt; //这里我绑到DataTable上了.     this.lngCatalogID.DataTextField = ...

  4. struts2中checkboxlist和radio的基本用法

    第一种用法: <s:checkboxlist name="b" list="#{'凤凰座':'一辉','双子座':'撒卡','白羊座':'史昂','天枰座':'童虎 ...

  5. checkboxlist控件用法

    CheckBoxList 控件比CheckBox要好用,我就不说为什么了,开玩笑说是因为  CheckBoxList比CheckBox多几个字母.嘻嘻.正经规范的话我不会说.我要做的就是利用数据绑定来 ...

  6. ListBox,CheckBoxList,DropDownList,RadioButtonList的常见用法

    http://www.cnblogs.com/youchun/archive/2009/12/27/1633655.html 转载于:https://www.cnblogs.com/modernsky ...

  7. ASP.NET中WebForm组件CheckBoxList编程

    作者:马金虎  来自:yesky CheckBox选择组件是一个程序中都经常的组件.在程序设计中使用到该组件,一般都不会只使用到一个,往往是以多个此类组件的形式出现的.在ASP.NET页面中如果要使用 ...

  8. ASP.NET页面的CheckBoxList组件

    CheckBox选择组件是一个程序中都经常的组件.在程序设计中使用到该组件,一般都不会只使用到一个,往往是以多个此类组件的形式出现的.在ASP.NET页面中如果要使用到多个CheckBox组件,除了添 ...

  9. WEB Struts2 中OGNL的用法

    2019独角兽企业重金招聘Python工程师标准>>> User对象属性获取 如User中有username和password字段 获取username属性<s:propert ...

最新文章

  1. 2019.01-02 总结
  2. python的函数式编程玩法+年末小感
  3. 【译】在Android中保护数据-加密大数据
  4. matlab电压稳定极限,电力系统电压稳定性的Matlab建模分析
  5. Python OOP:面向对象基础,定义类,创建对象/实例,self,创建多个对象,添加对象属性,访问对象属性,__init__方法,带参数的__init__,__str__方法,__del__方法
  6. IOS - plist使用
  7. TypeScript 素描 - 接口
  8. 信息技术是一把双刃剑,如何掌控好这柄剑?
  9. 如何快速将一个lista集合中的部分字段值组合成新的的listb部分*
  10. 计算机毕设周记20篇,电子与计算机毕业设计周记.doc
  11. KVM虚拟化技术原理简介
  12. 渲染的本质: 纹理过滤(Texture filtering)技术
  13. Android中,长度单位详解(dp、sp、px、in、pt、mm)具体解释与换算(1)
  14. 带通滤波器c5000汇编语言,基于SIW技术的高选择性带通滤波器的设计与实现
  15. Teardrop攻击 —— 创建虚假的IP数据包
  16. android jnl的mk文件,动态语言与静态语言
  17. 【coolshell酷壳】你可能不知道的Shell
  18. 超强 SVN 对比 excel 工具 Spreadsheet Compare使用方法
  19. Pandas(一)--Series结构
  20. 2.Matlab画好图后,如何插入到word里面去

热门文章

  1. JavaScript阻止链接跳转
  2. 查看服务器操作系统版本信息,查看服务器操作系统版本信息
  3. JPEG图片压缩的Python实现
  4. Why we need activation function?
  5. MyEclipse2017破解时 ACTIVATION_KEY为null
  6. 我们说的那些培训班,到底要不要报?自学编程VS培训报班
  7. openssl HeartBleed漏洞复现
  8. JS 中对象的深浅拷贝(ES3、ES5、ES6不同方法底层实现,一文搞清楚深浅拷贝面试常问题)
  9. cocos creator中FBX文件不可用显示asset invalid
  10. 解决虚拟机桥接网络没有 VMnet0 的问题