Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one repeater one page. Liek this

From To depart arrive operation

LHR JFK 25july 30aug ButtonDeleteSector
LHR JFK 25july 30aug ButtonDeleteSector
LHR JFK 25july 30aug ButtonDeleteSector

now, when I click particular button on particular row, then it should delete the clicked row. So I created this in html for the buttons

ASP.NET
<td class="ItemTemplate" style="text-align: left; width: 75px;">
<asp:Button ID="btnDeleteSector" runat ="server" Text="Delete Sector"  CommandName ="Delete" UseSubmitBehavior ="false"/>
</td>

And in the VB code
VB
Protected Sub rptDatabaseItinerary_Delete_Sector(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptDatabaseItinerary.ItemCommand

 If e.Item.ItemType = ListItemType.Item Then

           Dim btnDeleteSector As Button = CType(e.Item.FindControl("btnDeleteSector"), Button)

           Dim id As String = btnDeleteSector.CommandArgument

       End If

       If e.CommandName = "Delete" Then

           For Each objSector As Calrom.BLL.Common.BookingModel.Sector In DatabaseBookingPart.Sectors()

               If e.Item.ItemIndex = 0 Then
                   objSector.Status = BLL.Common.BookingModel.Status.Deleted
               End If


           Next
           rptDatabaseItinerary.DataBind()

       End If

   End Sub




but it is deleting the all sectors, Can anyone tell me how can i select the particualr row and delete it.
Posted

 
Share this answer
 
As well as a commandname, you need to give the button a CommandArgment that represents the ID of the data you want to delete. On the ItemCommand event of the repeater you check the commandname and commandargument and if the name is "Delete" you delete the record related to the ID held in the CommandArgument.
 
Share this answer
 
Comments
Member 11491784 4-Aug-15 5:26am    
but if there are more rows because it will dynamically generate buttons, it will delte other rows also
F-ES Sitecore 4-Aug-15 5:30am    
No, because each button has a commandargument that is unique to it. When you click a button the itemcommand event is fired once and it passes the commandname and commandargument of the button clicked. If you google for "repeater itemcommand event" you'll find examples.
Member 11491784 4-Aug-15 5:41am    
CommandName ="Delete" UseSubmitBehavior ="false" CommandArgument="<%# Container.ItemIndex.ToString()%>"
I added this bit in html to get command name and command argument.

And i am also handling the same in vb
For Each myitem As RepeaterItem In rptDatabaseItinerary.Items
Dim id As Button = CType(myitem.FindControl("btnDeleteSector"), Button)
If id.CommandName = "Delete" Then
// do stuff

End if


Next

e.command argument is also coming with unique id, But how can I know which button i pressed. Is there any event you know?
Because there can be many rows and rows id they are created at run time
F-ES Sitecore 4-Aug-15 6:11am    
The index isn't related to your data though. I'd made the commandargument the ID of the "Sector" record that row is bound to.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900