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 }