posted 1/2/2009 by Vijendra Shakya
Delete the multiple recored from repeter or datalist .
plz go through this example:
<asp:Button ID="bntDelete" runat="server" Text="Delete " CommandName="Delete" oncommand="bntDelete_Command" /> <br />
<asp:Repeater ID="repeater1" runat="server" DataMember="EmailID"> <HeaderTemplate> <tr> <th> <input type="checkbox" id="checkAll" onclick="CheckAll(this);" runat="server" name="checkAll"> <b>Select All</b> </th> <th> Email ID </th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <input type="checkbox" runat="server" id="chkId" onclick="CheckChanged();" checked='false' name="EmailID" /> </td> <td><asp:Label ID="Label 1" runat="server" Text=' <%#Eval("EmailID")%>'></asp:Label> </tr> </ItemTemplate> </asp:Repeater>
for the button click:
protected void bntDelete_Command(object sender, CommandEventArgs e) { if (e.CommandName.Equals("Delete")) { foreach (RepeaterItem ri in repeater1.Items) { HtmlInputCheckBox chkId = (HtmlInputCheckBox)ri.FindControl("chkId"); Label lblTemplateID = (Label)ri.FindControl("lblTemplateID"); if (chkId != null) { if (chkId.Checked) { //your delete code is here } } } PopulateEMP(); } }
If you want to delete the multiple record from the datalist the use the Datakeys property.
// put your delete button here it is not same as repeater.
<asp:Button ID="bntDelete" runat="server" Text="Delete EMP" />  
<asp:DataList ID="DataList 1" runat="server" DataKeyField="EmpID" CssClass="gridtable">
///same as repeater code is here
///
<asp:DataList>
Dlete button code is :
protected void btnDelete_Click(object sender, EventArgs e) { foreach (DataListItem di in DataList1.Items) { HtmlInputCheckBox chkId = (HtmlInputCheckBox)di.FindControl("chkId"); if (chkId != null) { if (chkId.Checked) { // your delete code is here. } } } PopulateEMP(); }
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18