This is a migrated thread and some comments may be shown as answers.

Add selected items to an ArrayList

4 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 08 Jul 2011, 12:53 PM
I have a radgrid which allows me to select multiple rows. I was wondering how I would get a column value from the selected rows and add them to an arraylist.

I have the following code behind for the radgrid already:

Protected Sub ToggleRowSelection(ByVal sender As Object, ByVal e As EventArgs)
        CType(CType(sender, CheckBox).NamingContainer, GridItem).Selected = CType(sender, CheckBox).Checked
    End Sub
 
    Protected Sub ToggleSelectedState(ByVal sender As Object, ByVal e As EventArgs)
        Dim headerCheckBox As CheckBox = CType(sender, CheckBox)
        For Each dataItem As GridDataItem In RequestFiles.MasterTableView.Items
            CType(dataItem.FindControl("CheckBox1"), CheckBox).Checked = headerCheckBox.Checked
            dataItem.Selected = headerCheckBox.Checked
        Next
    End Sub
 
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RequestFiles.PreRender
        lblCountRecords.Text = String.Format("<strong>{0}</strong>", RequestFiles.SelectedItems.Count)
    End Sub

So I want to get the value from column 2 and display as - 001, 002, 004, 005, 007.

This then needs to go into an email.

Something like. The files you requested were: 001, 002, 004, 005, 007

4 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 1
answered on 08 Jul 2011, 06:39 PM
Anyone? Can this be done. Any demos online?
0
Pavlina
Telerik team
answered on 12 Jul 2011, 01:02 PM
Hi Andrew,

To achieve the desired functionality you can save the index of rows where the checkbox resides in an ArrayList and then save in Session. Then you can simply access the corresponding rows using the indexes saved in the ArrayList.

Give it a try and let me know how it goes.

Greetings,
Pavlina
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Andrew
Top achievements
Rank 1
answered on 12 Jul 2011, 01:06 PM
Ok. but how do i save the indexes in an arraylist? This is what I dont understand.

Are you talking about then creating a sesson variable and using that?
0
Vasil
Telerik team
answered on 12 Jul 2011, 03:01 PM
Hello Andrew,

Check the example below.

Dim selectedItems As ArrayList
 
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
     
    If selectedItems Is Nothing Then
        selectedItems = New ArrayList
    Else
 
    If e.CommandName = RadGrid.SelectCommandName AndAlso TypeOf e.Item Is GridDataItem Then
        Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
        Dim customerID As String = dataItem.OwnerTableView.DataKeyValues(dataItem.ItemIndex)("CustomerID").ToString
        selectedItems.Add(customerID)
    End If
End Sub

You could see such approach used in this help topic:
http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-on-sorting.html

Kind regards,
Vasil
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Andrew
Top achievements
Rank 1
Pavlina
Telerik team
Vasil
Telerik team
Share this question
or