成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

ASP.NET CheckBoxList組件編程淺析

開發 后端
ASP.NET CheckBoxList組件編程主要想大家講述ASP.NET CheckBoxList的常用屬性使用和各自的特點以及學習的總結。

ASP.NET CheckBoxList組件編程的出現:CheckBox選擇組件是一個程序中都經常的組件。在程序設計中使用到該組件,一般都不會只使用到一個,往往是以多個此類組件的形式出現的。在ASP.NET頁面中如果要使用到多個CheckBox組件,除了添加多個CheckBox組件在頁面中之外,還有一種比較方便的方法,就是使用CheckBoxList組件。CheckBoxList組件是由一組的CheckBox組件組成的,在此組件中CheckBox是做為條目的形式出現的,并且對每個在CheckBoxList組件中的CheckBox都有一個索引號,這樣在程序中就更容易來處理了。

這時你可能要問,這不是多此一舉么,既然有了CheckBox組件,還要CheckBoxList組件干什么?這是因為在程序設計的過程中,處理CheckBoxList組件要往往要比處理CheckBox組件相對容易的多并且也明了的多。舉例如下:

假定有一個CheckBoxList組件和有十個CheckBox組件,并且這個CheckBoxList組件是由這十個CheckBox組件構成的。為了檢測這十個CheckBox組件中的哪些已經被選擇的,如果程序中選用的CheckBox組件就需要如下代碼:

  1.  if ( C1 . Checked )  
  2.  {  
  3.   }  
  4.  if ( C2 . Checked )  
  5.  {  
  6.   }  
  7.  ....  
  8.  if ( C10 . Checked )  
  9.  {  
  10.  }  

但如果程序中使用了CheckBoxList組件,就只需要以下這幾行代碼就可以了:

  1.  for ( int i = 0 ; i ﹤ CHK . Items . Count ; i++ )  
  2.  {  
  3.   if ( CHK . Items [ i ] . Selected )  
  4.   {  
  5.    //處理你要完成的工作  
  6.   }  
  7.  } 

注釋:其中C1 -- C10是CheckBox組件,CHK是CheckBoxList組件

可見用了CheckBoxList組件,在程序設計中的確更明了,更簡潔了。并且只要你掌握了CheckBoxList組 件的用法,CheckBox組件的用法大致也就會了。

一. 如何在創建一個ASP.NET CheckBoxList組件:

  1. ﹤asp:CheckBoxList runat = "server" id = C1 ﹥  
  2. ﹤asp:ListItem Value = 1 ﹥***個檢查框﹤/asp:ListItem ﹥  
  3. ﹤asp:ListItem Value = 2 ﹥第二個檢查框﹤/asp:ListItem ﹥  
  4. ﹤asp:ListItem Value = 3 ﹥第三個檢查框﹤/asp:ListItem ﹥  
  5. .....  
  6.  
  7. //注釋:在這里可以加入若干個檢查框  
  8.  
  9. ﹤/asp:CheckBoxList ﹥ 

在ASP.NET頁面中加入上面的語句,就可以產生一個名稱為"C1"的CheckBoxList組件了。

二. 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. }  

(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. {  

五. 文中源程序代碼(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.     
  9.    ﹤asp:Button Text = "提交" runat = "server" onclick = "Button_Click" /﹥  
  10.    ﹤h1 ﹥ ﹤font color = red ﹥ 你選擇的計算機語言類型為: ﹤/font ﹥ ﹤/h1 ﹥  
  11.    ﹤asp:Label id = lblResult runat = "server" /﹥  
  12.  ﹤/form ﹥  
  13.  ﹤/body ﹥  
  14. ﹤/html ﹥ 

六. ASP.NET CheckBoxList組件編程總結:

其實CheckBoxList組件也是一個服務器端組件。本文介紹了CheckBoxList組件中的一些主要的屬性和方法,并且通過一個比較典型的例子說明了在ASP.NET頁面中如何進行與CheckBoxList組件相關的編程,其實對于另外一個比較重要的組件--CheckBox來說,他們中有許多的相似之處,掌握了CheckBoxList組件的用法大致也就掌握了CheckBox組件的用法。

ASP.NET CheckBoxList組件編程的相關內容就向你介紹到這里,希望對你學習ASP.NET CheckBoxList組件編程有所幫助。

【編輯推薦】

  1. ASP.NET組件設計之生命周期詳解
  2. ASP.NET組件設計之傳輸機制淺析
  3. ASP.NET組件設計之復雜屬性和狀態管理淺析
  4. ASP.NET httpHandler使用淺析
  5. ASP.NET組件編程之事件編寫淺析
責任編輯:仲衡 來源: 網站愛好者協會
相關推薦

2009-08-05 18:36:12

ASP.NET Che

2009-08-10 16:07:44

ASP.NET Lin

2009-07-31 13:06:53

CheckBoxLisASP.NET頁面

2009-08-05 16:53:14

ASP.NET組件設計

2009-07-24 18:02:46

ASP.NET編程

2009-08-10 13:32:15

ASP.NET TimASP.NET組件設計

2009-08-10 15:26:46

ASP.NET組件編程

2009-08-03 13:38:18

ASP.NET編程模型

2009-08-05 16:59:55

ASP.NET組件設計

2009-08-03 13:12:34

ASP.NET編程模型

2009-07-27 13:34:15

ASP.NET編程

2009-08-05 15:50:13

ASP.NET優點

2009-07-31 12:43:59

ASP.NET MVC

2009-07-24 13:41:15

ASP.NET AJA

2009-08-10 14:38:29

ASP.NET組件設計

2009-08-03 16:57:42

ASP.NET編程規范

2009-08-03 17:07:13

ASP.NET編程規范

2009-08-03 11:21:47

ASP.NET編程模型

2009-08-03 18:00:00

ASP.NET服務器控

2009-07-28 15:53:43

ASP.NET Web
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 一区二区三区日韩 | 麻豆av网站 | 99久久久99久久国产片鸭王 | 日韩精品a在线观看图片 | 欧美精品一区二区三区视频 | 精品久久久久久久久亚洲 | 久久国内 | 久草网址 | 91夜夜夜| 国产激情在线 | 亚洲日本一区二区 | av资源网站 | 综合五月 | 日日日日日日bbbbb视频 | 精品一区二区三区免费视频 | 视频一区 亚洲 | 亚洲成人日韩 | 亚洲精品国产综合区久久久久久久 | 99爱在线 | 一级欧美一级日韩片免费观看 | 久久久久久久综合色一本 | 久久久久国产一区二区三区四区 | 中文字幕在线免费 | 亚洲在线一区 | 国产一区二区中文字幕 | 91一区二区三区在线观看 | 成年人在线视频 | 中文字幕一区二区三区在线视频 | 亚洲手机在线 | 欧美三级视频在线观看 | k8久久久一区二区三区 | 国产久| 久久国产精99精产国高潮 | 91精品久久 | 99精品视频在线 | 成人在线看片 | 久久亚洲视频 | 成人黄色电影免费 | 精品国产乱码久久久久久蜜柚 | 午夜码电影| 97视频网站 |