刪除JS前台校正,後台大量刪除

來源:互聯網
上載者:User

標籤:js   前台驗證   後台刪除   

1、功能需求

在一個資料表格中,選中欲刪除的記錄,點擊刪除按鈕,先觸發前台驗證,然後調用幕後處理邏輯

2、代碼實現

HTML代碼:

<asp:Repeater ID="repInputList" runat="server" DataSourceID="InputsDataSource"

           EnableViewState="true" >

       <HeaderTemplate>

           <table cellpadding="2" cellspacing="1" class="Admin_Table">

               <thead>

                   <tr class="Admin_Table_Title">

                       <th style="width: 5%;" align="center">

                           選擇

                       </th>

                          <th style="width: 6%;" align="center">

                           倉庫

                       </th>

                       <th style="width: 6%;" align="center">

                           物資

                       </th>

                       <th style="width: 5%;" align="center">

                           數量

                       </th>

                     </tr>

               </thead>

       </HeaderTemplate>

       <ItemTemplate>

           <tr onmouseover="this.style.backgroundColor=‘#ffff66‘;" onmouseout="this.style.backgroundColor=‘#d4e3e5‘;">

               <td>

                   <asp:CheckBox ID="cb" runat="server" name="checkbox" />

                   <asp:HiddenField ID="hfrkid" runat="server" Value=‘<%# Eval("rkid")%>‘ />

               </td>

                      <td  title=‘<%#Eval("wname") %>‘>

                     <%#StringTruncat(Eval("wname").ToString(), 8, "...")%>

               </td>

               <td title=‘<%#Eval("gname") %>‘>

                   <%#StringTruncat(Eval("gname").ToString(), 4, "...")%>

               </td>

               <td>

                   <%#Eval("rkamount") %>

               </td>

              </tr>

       </ItemTemplate>

       <FooterTemplate>

           </table></FooterTemplate>

   </asp:Repeater>

  <asp:Button ID="btnAllDel" runat="server" Text="刪除選中" OnClick="btnAllDel_Click" OnClientClick="return IFChecked();"

   ForeColor="Red" />


JS代碼:

//當函數返回false時,將不會調用背景btnAllDel_Click()方法

function IFChecked(){

      var count=  $("input:checkbox:checked").length;

      if (count<=0) {

     alert("請選擇要刪除的記錄!");

     return false;

      }else {

              return confirm("您確認要刪除選中的入庫單嗎?");

      }

    }


後台方法:

  protected void btnAllDel_Click(object sender, EventArgs e)

       {

           for (int i = 0; i < this.repInputList.Items.Count; i++)

           {

               RepeaterItem ri = this.repInputList.Items[i];

               CheckBox chb = ri.FindControl("cb") as CheckBox;

               string rkid = ((HiddenField)(ri.FindControl("hfrkid"))).Value;

               if (chb.Checked == true)

               {

                   inputdao.Delete(rkid);

                 

               }

           }

           Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script> alert(‘刪除成功!‘)</script>");

           rep_Bind();

       }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.