当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  ASP.NET中WebForm组件CheckBoxList编程(4)

 ASP.NET中WebForm组件CheckBoxList编程(4)

点击次数:15 次 发布日期:2008-11-26 15:33:01 作者:源代码网
源代码网推荐      五. 文中源程序代码(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 >
源代码网推荐      <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组件的用法。
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华