[Asp.net2.0]ASP.NET中WebForm組件CheckBoxList編程

來源:互聯網
上載者:User
是執行了下列來源程式代碼(Check.aspx)後,產生的介面:
  
  
  
    Check.aspx來源程式代碼如下:
  
  
  <% @ Page Language = "C#" %>
  
  <html >
  <head >
  <title > CheckBoxList組件示範程式 </title >
  <script runat = "server" >
   protected void Button_Click ( object sender , EventArgs e )
   {
    //組件中的檢查框中的文本和選框的排列位置
    switch ( cboAlign . SelectedIndex )
    {
     case 0 :
      ChkList . TextAlign = TextAlign . Left ;
      break ;
     case 1 :
      ChkList . TextAlign = TextAlign . Right ;
      break ;
    }
  
    //組件中各個檢查框布局
    switch ( cboRepeatLayout . SelectedIndex )
    {
     case 0 :
      ChkList . RepeatLayout = RepeatLayout . Table ;
      break ;
     case 1 :
      ChkList . RepeatLayout = RepeatLayout . Flow ;
      break ;
    }
  
    //組件中各個檢查框排列方向
    switch ( cboRepeatDirection . SelectedIndex)
    {
     case 0 :
      ChkList . RepeatDirection = RepeatDirection . Vertical ;
      break ;
     case 1 :
      ChkList . RepeatDirection = RepeatDirection . Horizontal ;
      break ;
    }
  
    //組件中各個檢查框的排列行數
    try
    {
     int cols = int . Parse ( txtRepeatCols.Text ) ;
     ChkList . RepeatColumns = cols ;
    }
    catch ( Exception )
    {
    }
  
    lblResult . Text = "" ;
    for ( int i = 0 ; i < ChkList . Items . Count ; i++ )
    {
     if( ChkList . Items [ i ] . Selected )
     {
      lblResult . Text += ChkList . Items [ i ] .Text + " <br > " ;
     }
    }
   }
   </script >
   </head >
   <body >
   <form runat = "server" >
    <h1 align = center > CheckBoxList組件示範程式 </h1 >
    <table >
     <tr >
      <td > 組件中的文本排列位置: </td >
      <td >
        <asp:DropDownList id = cboAlign runat = "server" >
         <asp:ListItem > 居左 </asp:ListItem >
         <asp:ListItem > 居右 </asp:ListItem >
        </asp:DropDownList >
      </td >
     </tr >
     <tr >
      <td > 組件中各個條目布局: </td >
      <td >
        <asp:DropDownList id = cboRepeatLayout runat = "server" >
         <asp:ListItem > 表格型 </asp:ListItem >
         <asp:ListItem > 緊湊型 </asp:ListItem >
        </asp:DropDownList >
      </td >
     </tr >
     <tr >
      <td> 組件中各個條目排列方向:</td >
      <td >
        <asp:DropDownList id = cboRepeatDirection runat = "server" >
         <asp:ListItem > 水平方向 </asp:ListItem >
         <asp:ListItem > 垂直方向 </asp:ListItem >
        </asp:DropDownList >
      </td >
     </tr >
     <tr >
      <td > 組件中各個條目排列行數: </td >
      <td > <asp:TextBox id = "txtRepeatCols" runat = "server" /> </td >
     </tr >
    </table >
    <br >
     請選擇你所需要學習的電腦語言類型:
    <br >
    <asp:CheckBoxList id = "ChkList" RepeatDirection = Horizontal runat = "server" >
     <asp:ListItem > Visual C++ .Net </asp:ListItem >
     <asp:ListItem > Visual C# </asp:ListItem >
     <asp:ListItem > VB.NET </asp:ListItem >
     <asp:ListItem > JScript.NET </asp:ListItem >
     <asp:ListItem > Visual J# </asp:ListItem >
    </asp:CheckBoxList >
    <br >
     <asp:Button Text = "提交" runat = "server" onclick = "Button_Click" />
     <h1 > <font color = red > 你選擇的電腦語言類型為: </font > </h1 >
     <asp:Label id = lblResult runat = "server" />
   </form >
   </body >
  </html >
  
  
    六. 總結:
  
    其實CheckBoxList組件也是一個伺服器端組件。本文介紹了CheckBoxList組件中的一些主要的屬性和方法,並且通過一個比較典型的例子說明了在ASP.NET頁面中如何進行與CheckBoxList組件相關的編程,其實對於另外一個比較重要的組件--CheckBox來說,他們中有許多的相似之處,掌握了CheckBoxList組件的用法大致也就掌握了CheckBox組件的用法。 
  
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.