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 ();
}