• Js 实战3(实现全选)


     1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
     2 
     3 <!DOCTYPE html>
     4 
     5 <html xmlns="http://www.w3.org/1999/xhtml">
     6 <head runat="server">
     7     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     8     <title></title>
     9 </head>
    10 <body>
    11     <form id="form1" runat="server">
    12         <div>
    13             <table style=" 100%; text-align: center; background-color: navy;">
    14                 <tr style="color: white;">
    15                     <td>全选
    16                         <input type="checkbox" id="ckall" />
    17                     </td>
    18                     <td>ids</td>
    19                     <td>pic</td>
    20                     <td>name</td>
    21                     <td>nowPrice</td>
    22                     <td>oldPrice</td>
    23                     <td>context</td>
    24                 </tr>
    25                 <asp:Repeater ID="Repeater1" runat="server">
    26                     <ItemTemplate>
    27                         <tr style="background-color: white;">
    28                             <td>
    29                                 <input type="checkbox" class="ck" name="ck" value="<%#Eval("ids") %>" />
    30                             </td>
    31                             <td><%#Eval("ids") %> </td>
    32                             <td><%#Eval("pic") %></td>
    33                             <td><%#Eval("name") %></td>
    34                             <td><%#Eval("nowPrice") %></td>
    35                             <td><%#Eval("oldPrice") %></td>
    36                             <td><%#Eval("context") %></td>
    37                         </tr>
    38                     </ItemTemplate>
    39                 </asp:Repeater>
    40             </table>
    41             <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    42             <asp:Button ID="Button1" runat="server" Text="删除" />
    43         </div>
    44     </form>
    45 </body>
    46 </html>
    47 <script type="text/javascript">
    48     document.getElementById("ckall").onclick = function () {
    49         var oCks = document.getElementsByClassName("ck");
    50         for (var i = 0; i < oCks.length; i++) {
    51             oCks[i].checked = this.checked;
    52         }
    53     };
    54 
    55     var ooCks = document.getElementsByClassName("ck");
    56 
    57     for (var i = 0; i < ooCks.length; i++) {
    58         ooCks[i].onclick = function () {
    59             var count = 0;
    60             for (var j = 0; j < ooCks.length; j++) {
    61                 if (ooCks[j].checked == false) {
    62                     count++;
    63                 }
    64             }
    65 
    66             if (count > 0) {
    67                 document.getElementById("ckall").checked = false;
    68             }
    69             else {
    70                 document.getElementById("ckall").checked = true;
    71             }
    72 
    73 
    74         };
    75     }
    76 </script>

     删除操作:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.UI;
     6 using System.Web.UI.WebControls;
     7 
     8 public partial class Default4 : System.Web.UI.Page
     9 {
    10     protected void Page_Load(object sender, EventArgs e)
    11     {
    12         if (!IsPostBack)
    13         {
    14             Repeater1.DataSource = new gouwuData().Select();
    15             Repeater1.DataBind();
    16         }
    17 
    18         Button1.Click += Button1_Click;
    19     }
    20 
    21     void Button1_Click(object sender, EventArgs e)
    22     {
    23         string s = Request["ck"];
    24         
    25         //Label1.Text = s;
    26         if (s != null)
    27         {
    28             string[] ss = s.Split(',');
    29             for (int i = 0; i < ss.Length; i++)
    30             {
    31                 new gouwuData().Delete(Convert.ToInt32(ss[i]));
    32             }
    33             Response.Redirect("Default4.aspx");
    34         }
    35         else
    36         {
    37             Label1.Text = "未选择数据!";
    38         }
    39     }
    40 }
  • 相关阅读:
    【推荐】微服务分布式企业框架Springmvc+mybatis+shiro+Dubbo+ZooKeeper+Redis
    将WCF寄宿在托管的Windows服务中
    剑指Offer
    剑指Offer
    Entity Framework 无法对没有主键的视图映射实体的解决办法
    设置Sql Agent运行Job时的执行账户
    IE中Keep-Alive机制引起的错误
    Ajax错误 “SCRIPT7002: XMLHttpRequest: 网络错误 0x2ef3, 由于出现错误 00002ef3 而导致此项操作无法完成” 的归纳总结
    在IIS站点中Adomd.net集成认证账号问题
    出现“不能执行已释放的Script代码”错误的原因及解决办法
  • 原文地址:https://www.cnblogs.com/maxin991025-/p/6278739.html
Copyright © 2020-2023  润新知