Part 66 - Check及Uncheck所有CheckBox 同时删除多行数据记录的实现
实现效果:勾选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: Studentpublic 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>
Part 66 - Check及Uncheck所有CheckBox 同时删除多行数据记录的实现相关推荐
- uniapp中checkbox复选框动态绑定数据
checkbox复选框动态绑定数据: <template><view class="box"><checkbox-group @change=&quo ...
- mfc中添加checkbox check、uncheck事件
得到复选框状态的函数:CButton* pBtn = (CButton*)GetDlgItem(IDC_CHECK); int state = pBtnNONE->GetCheck(); 当st ...
- html 遍历div内check,vue+element中checkbox 实现遍历分组全选
1.html部分 style="margin-left: 30px" :indeterminate="item.isIndeterminate" v-model ...
- html check选中状态,html checkbox选中
JS 怎么控制 checkbox 选中 JSP中如何获取checkbox的状态(选中或非选中)? [code=html] C#获得HTML中选中的 checkbox html控制checkbox选择个 ...
- html 为checkbox添加check函数,html 里 checkbox里 只要选中就会自动添加checked=“checked”么?...
事实上HTML代码是不会发生变化的,但是控件对象的属性会发生变化以反映这个操作的结果.也就是说,该对象的checked属性值会由false变成true.但元素标签中并不会插入checked=" ...
- Extjs checkbox 多删除
var BankOrderstore = new Ext.data.JsonStore //数据源({url: "../Handler/TxnRefund.ashx",totalP ...
- C# ListView控件显示表格(自适应宽度),添加 Checkbox,删除选择项,选中颜色和鼠标滑过背景变色
本文转载自:http://www.liangshunet.com/ca/201309/586362553.htm 亮术网 2020-03-07 本网原创 DataGridView控件功能十分强大,显示 ...
- asp.net Repeater取得CheckBox选中的某行某个值的c#写法
1. foreach (Control c in this.rptTables.Controls) { CheckBox cbx = (CheckBox)c.FindControl("cbx ...
- jquery复选框checkbox实现删除
实现这样一个基本需求,页面有很多数据,可以删除一条或多条,删除前判断是否选中至少一条,否则提示. function deleteUser() { //当时是想把内容以str+="" ...
- php怎么删除多条,php 用checkbox一次性删除多条记录的方法
一个简单示例 现有一个学生信息数据库,需要一次性删除多条记录 创建一个名为del.php的文件 代码如下: $link=mysql_connect("localhost",&quo ...
最新文章
- FM:代谢无机硫化合物的古菌Ferroplasma可介导细胞外电子传递
- Python广度优先查找和深度优先查找(内附python教程分享)
- 一则鬼故事:如果全世界程序员都消失了
- Mysql中查询速度的优化
- MySql绿色版安装过程记录
- servletcontext 使用解析
- ArcGIS Engine 刷新问题
- python 工具箱_Python交易工具箱:通过指标子图增强图表
- pthread_cond_wait的spurious wakeup问题
- NCRE四级网络工程师考题详解----目录分解法
- 选择题:JAVA的类和对象
- 网抑云音乐.ncm加密格式转换mp3
- textview 属性大全
- 计算机网络原理——传输层TCP协议的十个重要特性之保证可靠性的机制(确认应答和超时重传)
- 汇编启蒙题--by cyl老师
- Appops权限管理
- 怎么用网线连接开发板
- windows录屏_录屏软件:如何录制游戏视频?简单方法了解下
- 打造爆款产品只需四步,学会你也能爆单
- 爬虫实战——起点中文网小说的爬取