2

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?

3 Answers 3

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.