Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > asp.net DataList 复选框 也玩 全选反选全不选 by shawl.qiu
【标  题】:asp.net DataList 复选框 也玩 全选反选全不选 by shawl.qiu
【关键字】:asp.net,DataList,by,shawl.qiu
【来  源】:http://blog.csdn.net/btbtd/archive/2007/03/07/1523695.aspx

asp.net DataList 复选框 也玩 全选反选全不选 by shawl.qiu

Your Ad Here

asp.net DataList 复选框 也玩 全选反选全不选 by shawl.qiu


入乡随俗呀, 既然使用 asp.net 就要使用 asp.net 的模式处理问题...
详细看代码...

shawl.qiu
2007-03-07
http://blog.csdn.net/btbtd

  1. <%@ Page Language="C#AutoEventWireup="True" %>
  2. <%@ import Namespace="System.Data" %>
  3. <script runat="server">
  4.  void Page_Load(Object s, EventArgs e)
  5.  {
  6.   DataTable dt = new DataTable();
  7.   dt.Columns.Add(new DataColumn("id", typeof(int)));
  8.   DataRow dr;
  9.   
  10.   for(int i=0; i<10; i++)
  11.   {
  12.    dr = dt.NewRow();
  13.    dr[0] = i;
  14.    dt.Rows.Add(dr);
  15.   }
  16.   if(!IsPostBack)
  17.   {
  18.    listAtDataList.DataSource = dt;
  19.    listAtDataList.DataBind();
  20.   }
  21.  } // end Page_Load
  22.  
  23.  private void SelectAllCbxForDataList(DataList dl, string cbxId)
  24.  {
  25.   for(int i=0, j=dl.Items.Count; i<j; i++)
  26.   {
  27.    CheckBox cbx = (CheckBox)dl.Items[i].FindControl(cbxId);
  28.    cbx.Checked = true;
  29.   }
  30.  } // end private void SelectAllCbxForDataList
  31.  
  32.  private void UnSelectAllCbxForDataList(DataList dl, string cbxId)
  33.  {
  34.   for(int i=0, j=dl.Items.Count; i<j; i++)
  35.   {
  36.    CheckBox cbx = (CheckBox)dl.Items[i].FindControl(cbxId);
  37.    cbx.Checked = false;
  38.   }
  39.  } // private void UnSelectAllCbxForDataList
  40.  
  41.  private void SelectReverseCbxForDataList(DataList dl, string cbxId)
  42.  {
  43.   for(int i=0, j=dl.Items.Count; i<j; i++)
  44.   {
  45.    CheckBox cbx = (CheckBox)dl.Items[i].FindControl(cbxId);
  46.    if(cbx.Checked == true)cbx.Checked = false;
  47.    else cbx.Checked = true;
  48.   }
  49.  }
  50.  
  51.  private void CbxSleForDl(Object s, CommandEventArgs e)
  52.  {
  53.   switch(e.CommandName)
  54.   {
  55.    case "all":
  56.     SelectAllCbxForDataList(listAtDataList, "optCheckBox");
  57.     break;
  58.     
  59.    case "none":
  60.     UnSelectAllCbxForDataList(listAtDataList, "optCheckBox");
  61.     break;
  62.     
  63.    case "reverse":
  64.     SelectReverseCbxForDataList(listAtDataList, "optCheckBox");
  65.     break;
  66.   }
  67.  }
  68. </script>
  69. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  70. <html xmlns="http://www.w3.org/1999/xhtml">
  71. <head>
  72. <meta http-equiv="Content-Typecontent="text/html; charset=utf-8" />
  73. <title>shawl.qiu template</title>
  74. </head>
  75. <body>
  76.  <form runat="server">
  77.   <div class="cbxSle algr ">
  78.    <asp:Button id=SelectAllButton runat=server 
  79.     Text="all"
  80.     CommandName = "all"
  81.     OnCommand = CbxSleForDl
  82.     />
  83.    <asp:Button id=UnSelectAllButton runat=server 
  84.     Text="none"
  85.     CommandName = "none"
  86.     OnCommand = CbxSleForDl
  87.     />
  88.    <asp:Button id=SelectReverseButton runat=server 
  89.     Text="reverse"
  90.     CommandName = "reverse"
  91.     OnCommand = CbxSleForDl
  92.     />
  93.   </div
  94.   <br clear="both" />
  95.   
  96.   <ol>
  97.   <asp:DataList id="listAtDataList"
  98.    BorderColor="black"
  99.    CellPadding="5"
  100.    CellSpacing="5"
  101.    RepeatDirection="Horizontal"
  102.    RepeatLayout="Flow"
  103.    RepeatColumns="10"
  104.    ShowBorder="True"
  105.    runat="server">
  106.   
  107.    <HeaderTemplate>
  108.     <h3 class="algr">fan for this</h3>
  109.    </HeaderTemplate>
  110.    
  111.    <HeaderStyle>
  112.    </HeaderStyle>
  113.   
  114.    <AlternatingItemStyle CssClass="atListAlSty">
  115.    </AlternatingItemStyle>
  116.     
  117.    <ItemTemplate
  118.     kkkkkkkkkkk
  119.     <li><asp:CheckBox id=optCheckBox runat=server /></li>
  120.    </ItemTemplate>
  121.   <%--
  122.    <SeparatorTemplate
  123.    </SeparatorTemplate>
  124.   --%>
  125.    <FooterTemplate>
  126.    </FooterTemplate>
  127.   </asp:DataList>
  128.   </ol>

  129.  </form>
  130. </body>
  131. </html>




微软(北京).NET俱乐部第十二次技术沙龙:【上一篇】
域环境下,统一桌面和Windows基本的外观设置:【下一篇】
【相关文章】
  • Log actively being archived by another process
  • Step by Step构建嵌入式Linux系统平台
  • Asp.net 备份、还原Ms SQLServer及压缩Access数据库
  • Ruby on Rails学习拾遗(二)—函数的代码块和迭代器
  • sqEditor HTML 编辑器 for .net v1.0 By shawl.qiu
  • asp.net 中 使用 ado 的 Recordset GetString 函数 By shawl.qiu
  • 花了一段时间整理和使用的提高ASP.NET效率的几个方面(希望大家拍砖)
  • How to retrieve DELL Computer Service Tag by WMI programming
  • Asp.NET 生成随机码
  • 技巧/诀窍:把ASP.NET安全与经典ASP和非ASP.NET URLs集成
  • 【随机文章】
  • 网吧双线接入(ISP多链路复用)
  • 妙用M3U播放Winamp列表文件
  • 如何使用C#在发送往client的内容上加js代码
  • 红旗4.1桌面版安装过程
  • 从网友那里看来的几道有意思的题
  • ASP.NET 2.0数据教程之四:: 使用ObjectDataSource展现数据
  • autofs配置
  • 你会用sizeof吗?(vc篇)
  • 给freebsd系统增加一个新硬盘
  • SQL中DATALENGTH 用法
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.