日期:2009-11-07  浏览次数:20453 次

    五. 文中源程序代码(Check.ASPx)和执行的界面:
  
    下图是执行了下列源程序代码(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 >