Part 66 - Check及Uncheck所有CheckBox 同时删除多行数据记录的实现
来源:互联网 发布:淘宝贷款没还会怎么样 编辑:程序博客网 时间:2024/05/29 19:02
实现效果:勾选Name左边的CheckBox(后面部分简称‘它’),则所有CheckBox都会被选中, 再次Unckeck它,所有都不被选中;如果其他所有CheckBox都选中了,Name左边的CheckBox会自动选中;反之,如果其他的没有全部被选中,则它不会被自动选中或者由自动Uncheck.
Controller代码如下:
using MVC_DeleteMultiRow.Models;using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using MVC_DeleteMultiRow;using MVC_DeleteMultiRow.Models;namespace MVC_DeleteMultiRow.Controllers{ public class StudentController : Controller { SampleEntities db = new SampleEntities(); // GET: Student public ActionResult Index() { return View(db.Students.ToList()); } public ActionResult Delete(IEnumerable<int> employeeIdsToDelete) { List<Student> stul=db.Students.Where(x => employeeIdsToDelete.Contains(x.ID)).ToList(); foreach(Student item in stul) { db.Students.Remove(item); } db.SaveChanges(); return RedirectToAction("Index"); } }}Controller对应的View代码如下,其中JS和JQuery部分实现Check及Uncheck所有CheckBox的功能
@model IEnumerable<MVC_DeleteMultiRow.Models.Student>@{ ViewBag.Title = "Index";}<h2>Employee List</h2>@using (Html.BeginForm("Delete", "Student", FormMethod.Post)){ <table border="1"> <thead> <tr> <th> <span style="background-color: rgb(255, 255, 153);"> <input type="checkbox" name="checkAll" id="checkAll"></span> </th> <th> Name </th> <th> Gender </th> <th> Email </th> </tr> </thead> <tbody> @*@Html.EditorForModel()*@ @foreach(var item in Model) { <tr> <td> <span style="background-color: rgb(255, 255, 153);"><input type="checkbox" name="employeeIdsToDelete" id="employeeIdsToDelete" value="@item.ID"></span> </td> <td> @item.Name </td> <td> @item.Name </td> <td> @item.Name </td> </tr> } </tbody> </table> <input type="submit" id="btnSubmit" name="btnSubmit" value="Delete Selected students"/>}<span style="background-color: rgb(255, 255, 204);"><script src="~/Scripts/jquery-1.10.2.min.js"></script><script type="text/javascript" language="javascript"> $(function () { $("#checkAll").click(function () { $("input[name='employeeIdsToDelete']").prop("checked", this.checked); }); $("input[name='employeeIdsToDelete']").click(function () { if ($("input[name='employeeIdsToDelete']").length == $("input[name='employeeIdsToDelete']:checked").length) { $("#checkAll").prop("checked", true); } else { //$("#checkAll").removeAttr("checked"); $("#checkAll").prop("checked", false); } }); $("#btnSubmit").click(function () { var count = $("input[name='employeeIdsToDelete']:checked").length; if (count == 0) { alert("No rows selected to delete"); return false; } else { return confirm(count + " row(s) will be deleted"); } }); });</script> </span>
0 0
- Part 66 - Check及Uncheck所有CheckBox 同时删除多行数据记录的实现
- GridView控件与CheckBox结合,实现全选功能,同时实现删除选中的多行数据
- GridView控件与CheckBox结合,实现全选功能,同时实现删除选中的多行数据 .
- mfc中添加checkbox check、uncheck事件
- How to check and uncheck a checkbox with jQuery
- QTableView实现同时删除被选中的多行记录
- QTableView实现同时删除被选中的多行记录
- MSFlexGrid 实现删除连续选择的多行数据。
- MSFlexGrid 实现删除连续选择的多行数据。
- GridView控件的CheckBox选定删除记录,总是无法实现
- 统计所有表的记录行数
- check异常和uncheck异常的区别b
- html:checkbox无法uncheck
- 获取datagridview中checkbox选中的多行数据
- java 利用checkbox多选按钮实现多条记录同时操作
- check exception和uncheck exception
- check exception和uncheck exception
- check exception和uncheck exception
- Python笔记--tuple
- RelativeLayout常用属性介绍
- c语言的文法产生式
- 对“移动产品经理”的理解
- java 常见的单例模式,推荐静态内部类
- Part 66 - Check及Uncheck所有CheckBox 同时删除多行数据记录的实现
- VS2013安装opencv-2.4.13
- spring整合mybatis升级
- Java的动态代理(dynamic proxy)
- Android Multimedia框架总结(五)多媒体基础概念
- 为什么不能在子线程中更新UI
- 字符串倒序
- apache学习一安装
- 一起来写web server 03 -- 多线程版本