码迷,mamicode.com
首页 > Windows程序 > 详细

C# 实现批量删除功能

时间:2020-06-29 14:59:03      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:rip   NPU   class   hang   code   join   inpu   rem   ati   

<input type="submit" class="btn btn-info" onclick="DelAll()" value="批量删除" />
 <table class="table table-striped" id="table">
        <tr>
            <td><input id="cb_selAll" type="checkbox" /></td>
            <td>ID</td>
        </tr>
        <tbody id="tb_body">
            @foreach (var item in Model)
            {
                <tr>
                    <td><input type="checkbox" value="@item.id" class="cb_fruit" /></td>
                    <td id="id">@item.id</td>
                </tr>
            }
        </tbody>
    </table>
<script>
    $(function () {
        $("#cb_selAll").change(function () {
            $("#tb_body :checkbox").prop("checked", this.checked);
        });
    });
    function DelAll() {
        var id = [];
        $("#tb_body :checkbox:checked").each(function () {
            id.push($(this).val());
        });
        $.ajax({
            url: "/Employees/DelAll",
            type: "GET",
            data: { id: id.join(",") },
            success: function (data) {
                if (data > 0) {
                    alert("成功!");
                    $("#tb_body :checkbox:checked").parent().parent().remove();
                    location.reload();
                } else {
                    alert("失败!");
                }
            },
            error: function () {
                alert("系统繁忙!");
            }
        });
    }
</script>
        /// <summary>
        /// DelAll
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public int DelAll(string id = "0")
        {
            string[] datalist = id.Split(,);//定义数组
            List<string> list = new List<string>();
            foreach (var item in datalist)
            {
                string data = "" + item.ToString() + "";
                list.Add(data);
            }
            string sql = string.Format("delete from Table where Id in(" + string.Join(",", list) + ")", list);
            return db.ExecuteNonQuery(sql);
        }

 

C# 实现批量删除功能

标签:rip   NPU   class   hang   code   join   inpu   rem   ati   

原文地址:https://www.cnblogs.com/BlackAgg/p/13207806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!