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

[Solved] RadGrid multi row select values

2 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Quintin
Top achievements
Rank 1
Quintin asked on 26 Feb 2010, 10:54 PM
I've got a grid where multiple rows can be selected. Once the user has selected the information on the grid, I need to cycle through all the selected items to get the datakeys values.

Tried the following in the button event
cId = RadGrid1.SelectedItems(0).OwnerTableView.DataKeyValues(RadGrid1.SelectedItems(0).ItemIndex)("CompilationId") 
 which returns no data (expecting a Guid)

however, doing the following does return a value
cId = RadGrid1.SelectedValues("CompilationId") 

But that only works for a single row selection. What I am trying to do is similar to the following
'Get number of selected items  
selectedItems = RadGrid1.SelectedItems.Count -1  
 
'Get value of DataKey for each selected row  
For i As Integer = 0 To selectedItems  
    cId = RadGrid1.SelectedItems(i).OwnerTableView.DataKeyValues(RadGrid1.SelectedItems(i).ItemIndex)("CompilationId")  
    'update the information  
    'loop or exit  
Next 

Something like that... could anyone help (a little time senitive).

Thanks
Q

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Mar 2010, 05:49 AM
Hi,

Please try the code snippet below to access the Selected Items and their corresponding Datakey values as shown below:

C#
  protected void Button1_Click(object sender, EventArgs e) 
    { 
        foreach (GridDataItem dataItem in RadGrid1.SelectedItems) 
        { 
          string selectedValue=   dataItem.GetDataKeyValue("CategoryName").ToString(); 
        } 
    } 


Thanks,
Princy
0
Quintin
Top achievements
Rank 1
answered on 01 Mar 2010, 11:30 AM
Thank you! Yes. Perfectly and a much simpler construct than the online example
 Here's VB version:
For Each dataItem As GridDataItem In RadGrid1.SelectedItems  
                    compilationId  = dataItem.GetDataKeyValue("CompilationId")  
                Next 
 BTW... compilationId (declared prior to this block) in the above example is a Guid, for string, as per C# example, add the .toString
Tags
Grid
Asked by
Quintin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Quintin
Top achievements
Rank 1
Share this question
or