KoolKabin
KoolKabin

Reputation: 17663

Adding Checkbox in asp.net Listview control to allow multiple delete

I am trying to display checkboxes in front of every row in list view. So that after selecting the desired checkboxes user clicks on delete button and we should delete that records.

but how can it be done?

Upvotes: 2

Views: 10583

Answers (3)

KoolKabin
KoolKabin

Reputation: 17663

Add Checkbox in markup

<asp:CheckBox ID="ChkSelect" runat="server" />

code behind as follows:

Dim ChkSelect As CheckBox = Nothing
Dim ListItem As ListViewDataItem = Nothing
Dim ItemList As List(Of Person) = New List(Of Person)
Dim Item As Person= Nothing

    For Each ListItem In MyDataList.Items
        ChkSelect = ListItem.FindControl("ChkSelect")
        If ChkSelect.Checked Then

            Dim UIN As Integer = _
              MyDataList.DataKeys(ListItem.DisplayIndex).Value.ToString()
            Item = Persons.GetData(UIN)
            Item.Deleted = True
            ItemList.Add(Item)

        End If
    Next
    Data = Persons.UpdateBulk(ItemList)
    If Data = True Then
        BindMyData()
    End If

Upvotes: 1

hallie
hallie

Reputation: 2845

I use GridView Template if I want to do that in GridView...try to look if theres ListView Template if there is.

Upvotes: 0

Slavo
Slavo

Reputation: 15463

You need to create a template for the items in the ListView, put the checkbox in it, and then get all the items that were checked when you click the Delete button. You could either keep track of the selected items on the client or the server, but it would always require some work to persist them.

Here's an article on using templates with the ListView: http://msdn.microsoft.com/en-us/library/bb398790.aspx#CreatingTemplatesForTheListViewControl

Upvotes: 0

Related Questions