I have a ListView and I have set up my Delete Link button. When I clicked Delete however I get "The ListView 'ListView' raised event ItemDeleting which wasn't handled." So I decided to try and implement the DeleteLinkButton_Click() and ListView_ItemDeleted() … however I can’t figure out how to identify which row I’ve selected for my DeleteLinkButton_Click().
I didn’t bind my source through a control instead I used the following method.
ListView.DataSource = myObject.RetreiveInfo()
ListView.DataBind()
I figure if I can identify my row I can access the values of the labels there and pass them to a stored procedure and perform my DELETE.
Can anyone help? If I need to provide more code just let me know!
Edit:
CodeBehind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
UpdateDisplay()
End If
End Sub
Protected Sub UpdateDistplay()
ListView.DataSource = myObject.RetrieveInfo()
ListView.DataBind()
End Sub
ASPX Page
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="DeleteLinkButton" Text="Delete" CommandName="Delete" OnClientClick="return confirm('Delete this Info?')" runat="server"></asp:LinkButton>
</td>
<td>
<asp:Label ID="Name" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</td>
</tr>
</ItemTemplate>
You can find out the index of the item being deleted in the ItemDeleting event, so handling that first might help you out a bit more. It looks like this:
At this point, you now have the index of the item whose delete button was clicked, so you can look up the label and perform the
DELETE(as you mentioned in your question).Good luck!