简体   繁体   中英

Deleting Selected ListViewItems from the Database

I have a ListView that I populate from the database. The ListView has a Checkbox on each row which is a built-in property of ListView .

I have been trying to get the text from the ID column next to the Checkbox which I will use in deleting the respective rows from the database but it all fails. I thought I could get the ListView.CheckedIndices and use them in return to point to the SelectedText of each index.

However all fails. More specifically i wanted to use the OnItemDeleting Event of list view but the ListView I have does not seem to have such event.

Is there any way i can achieve this?

I have had this problem before. What I did was this below:

<asp:ListView ID="xyz" runat="server">
    <ItemTemplate>
        <asp:LinkButton runat="server" ID="blah" OnClick="blah_Click" 
                        CommandArgument="<%# myObject.Id %>" /> 
    </ItemTemplate>
</asp:ListView>

I got the passed id through the command argument.Then I deleted the selected item and refreshed the data for listView . I am sure there must be a cleaner way of doing it.
Let me know how it goes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM