views:

659

answers:

3

Hi,

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?

A: 

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

Slavo
A: 

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

hallie
A: 

Add Checkbox in markup

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
KoolKabin