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

Get Grid Values in SelectedIndexChanged

4 Answers 295 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric Turner
Top achievements
Rank 1
Eric Turner asked on 25 Mar 2009, 03:01 PM
I have a RadGrid that I want to select a row, click a button and use the values from the selected row somewhere else.  I am able to highlight the row and SelectedIndexChanged fires but I cannot seem to get the correct syntax to get the data from the grid.  I am using the following example in C# I found in the fourm.  I want to convert this to VB.

I can't get the Format Code block to work correctly so it's a little sloppy...

Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.SelectedIndexChanged

foreach (GridDataItem item in   RadGrid1.MasterTableView.Items) 

{ If (item.Selected) Then 

        {  

            string strTxt = item["ProductName"].Text;  

        }

}

 

 

End Sub

I am able to do this and loop through each row in the grid.  It will loop through 10 times which is the number of rows in the grid:

 For Each GridDataItem RadGrid1.MasterTableView.Items

  'Do something here
Next 

 

 

But when I try to define the "item" I get errors.  I tried this:

For Each Item As GridDataItem In RadGrid1.MasterTableView.Items 

   'Do Something Here   Next

And This:
Dim Item As GridDataItem (I get error here telling me GridDataItem is not defined)

For Each GridDataItem In RadGrid1.MasterTableView.Items
   'Do Something Here  

 

Next

 

 

What Am I missing here?


4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Mar 2009, 06:06 AM
Hello Eric,

You can try the following code to access the selected row data on the SelectedIndexChanged event of the grid or button click event
c#:
         For Each item As GridDataItem In RadGrid1.SelectedItems 
             Dim strTxt As String = item("ProductName").Text 
             
         Next 

Thanks
Princy.
0
Eric Turner
Top achievements
Rank 1
answered on 26 Mar 2009, 02:21 PM
Thanks Princy, but it still tells me that GridDataItem is not defined.  If I take the "Item As" out and mouseover GridDataItem it tells me it is a type of object but when I put "item As"Is in it goes to not defined.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Mar 2009, 06:40 AM
Hi Eric,

I am not sure what exactly is the issue. The above given code is working fine on my end. Can you confirm that you have added the correct NameSpace in the code behind page.

 
Imports Telerik.Web.UI 


Thanks
Shinu.
0
Eric Turner
Top achievements
Rank 1
answered on 27 Mar 2009, 01:15 PM
OK, I feel really STUPID now!  That was the problem.

Thanks
Tags
Grid
Asked by
Eric Turner
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Eric Turner
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or