• repeater 结合checkbox批量删除


    项目中用到这个,从网上搜了搜相关内容,代码如下

    <script type="text/javascript">
    function checkAllThis(obj) {
    var aa = document.getElementsByTagName("input");
    for (var i = 0; i < aa.length; i++) {
    var e = aa[i];
    if ((e.type == 'checkbox')) {
    var o = e.name.lastIndexOf('ckbIndex');
    if (o != -1) {
    e.checked = obj.checked;
    }
    }

    }
    }
    </script>

    <form id="form1" runat="server">
    <div>
    <div style=" margin:0 0 6px 0px; 805px;">
    <asp:DropDownList ID="DropDownList1" runat="server">
    </asp:DropDownList>
    <asp:Button ID="Button1" runat="server" Text="筛选分类" OnClick="Button1_Click" />
    </div>

    <asp:Repeater runat="server" ID="Repeater1">
    <HeaderTemplate>
    <table width="805" height="53" border="0" cellpadding="0" cellspacing="1" bgcolor="#E2E2E2">
    <tr>
    <td width="143" height="30" align="center" bgcolor="#FFFFFF" class="b1">批量选择<input type="checkbox" id="checkAll" onclick="checkAllThis(this);" /></td>
    <td width="543" height="30" align="center" bgcolor="#FFFFFF" class="b1">新闻标题</td>
    <td width="142" align="center" bgcolor="#FFFFFF" class="b1">日期</td>
    <td width="56" align="center" bgcolor="#FFFFFF" class="b1">修改</td>
    <td align="center" bgcolor="#FFFFFF" class="b1" style=" 59px">删除</td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td height="26" align="center" bgcolor="#FFFFFF">
    <asp:CheckBox ID="ckbIndex" runat="server" /><%--<%#Eval("n_Title")%>--%><asp:HiddenField
    ID="hidValue" Value='<%#Eval("n_ID") %>' runat="server" />
    </td>
    <td height="26" align="center" bgcolor="#FFFFFF"><%#Eval("n_Title")%></td>
    <td align="center" bgcolor="#FFFFFF"><%#Eval("n_time")%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="News_Edit.aspx?n_ID=<%#Eval("n_ID")%>&n=edit">修改</a></td>
    <td align="center" bgcolor="#FFFFFF">



    <a href='News_Edit.aspx?n_ID=<%#Eval("n_ID")%>&n=del' onclick="return confirm('确定删除吗')">删除</a>

    </td>
    </tr>

    </ItemTemplate>
    <FooterTemplate>
    </table>
    </FooterTemplate>
    </asp:Repeater>
    <div style="805px; padding:5px;">
    <asp:Button ID="btnDelete" runat="server" Text="批量删除"
    OnClientClick="return confirm('确定删除吗')" onclick="btnDelete_Click" />
    </div>
    <div style=" margin:10px 0 0 200px; 805px;">
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>


    </div>
    </form>

    cs代码如下:

    protected void btnDelete_Click(object sender, EventArgs e)
    {
    string getid = "";
    for (int i = 0; i < Repeater1.Items.Count; i++)
    {
    CheckBox cb = Repeater1.Items[i].FindControl("ckbIndex") as CheckBox;
    HiddenField hd = Repeater1.Items[i].FindControl("hidValue") as HiddenField;
    if (cb.Checked)
    {
    getid += hd.Value + ",";

    }


    }
    if (getid == "")
    {
    Response.Write("<script>alert('请选择删除内容');history.go(-1)</script>");
    return;

    }
    getid = getid.Substring(0, getid.Length - 1);
    string sql = "delete from News where n_ID in("+getid+")";
    Class1.ExecSql(sql);
    Class1.AlertShow("删除成功", "News_Manage.aspx");


    }

  • 相关阅读:
    腾讯2017校招编程:一个数等于两个素数的和
    人类简史:从动物到上帝
    讨论:研发团队到底应该是制定OKR还是制定KPI?
    绩效主义毁了索尼
    研发团队是该制定OKR还是KPI?
    一切不行,都是“人”的不行?
    能力陷阱:能力越强,越容易失败
    一个好的产品经理到底有多么重要?
    管理:不会把目标翻译成任务,要你何用?
    做一个有产品思维的研发:Scrapy安装
  • 原文地址:https://www.cnblogs.com/wanshutao/p/4353445.html
Copyright © 2020-2023  润新知