Delete JS foreground check, background bulk Delete

Source: Internet
Author: User

1. Functional Requirements

In a data table, select the record that you want to delete, click the Delete button, trigger the foreground validation, and then invoke the background processing logic

2. Code implementation

HTML code:

<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" >

Choose

</th>

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

Warehouse

</th>

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

Material

</th>

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

Number

</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= "Delete selected" onclick= "Btnalldel_click" onclientclick= "return Ifchecked (); "

Forecolor= "Red"/>


JS Code:

When the function returns false, the background Btnalldel_click () method is not called

function ifchecked () {

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

if (count<=0) {

Alert ("Please select the record you want to delete!") ");

return false;

}else {

Return confirm ("Are you sure you want to delete the selected inbound orders?") ");

}

}


Background method:

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 (' Delete succeeded! ') </script> ");

Rep_bind ();

}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.