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

Select first row and pass ID (VB)

4 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 11 Apr 2009, 05:11 AM
Hi,

When the grid loads or is paged or sorted - I need to have the first row selected and to be able to pass the ID of that row to a seperate details section on the same page. (The ID is taken by a data reader which populates some labels) - Is this possible please?

For selecting the row, I tried converting the SelectFirstGridRow from the WebMail demo but in VB 'OfType' was not available.

private void SelectFirstGridRow()  
    {  
        GridDataItem firstDataItem = RadGrid1.Items.OfType<GridDataItem>().FirstOrDefault();  
        if (firstDataItem != null)  
            firstDataItem.Selected = true;  
    }  
 
 
Private Sub SelectFirstGridRow()  
    Dim firstDataItem As GridDataItem = RadGrid1.Items.OfType(Of GridDataItem)().FirstOrDefault()  
    If firstDataItem <> Nothing Then  
        firstDataItem.Selected = True 
    End If  
End Sub  
 
 

Cheers, Jon


4 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 Apr 2009, 02:54 PM
Hello jon byron,

The OfType() extension method is supported both in C# and in VB.

I am sending you a small sample with a page in C# and in VB showing how to select the first item programmatically using linq expressions.

I hope this helps.

All the best,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
John Davis
Top achievements
Rank 2
answered on 26 Nov 2009, 04:18 AM
Tsvetoslav

When page loads I need to select first row of the grid plus get values from this first row.

I can select the first row in the code:

protected

 

void RadGrid1_PreRender(object sender, EventArgs e)

 

{

RadGrid1.MasterTableView.Items[0].Selected =

true;

 

}

BUT, how can I get values from columns in this first row?  Is it possible to get them from the grid?  Or do I have to get it from the data source independent of the grid?

Steve

0
Princy
Top achievements
Rank 2
answered on 26 Nov 2009, 05:41 AM
Hi Steve,

Try out the following code to achieve the required:
c#:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.Items[0].Selected = true
        GridDataItem dataItem = (GridDataItem)RadGrid1.MasterTableView.Items[0]; 
        string strtxt = dataItem["ColumnUniqueName"].Text; 
    } 

Thanks
Princy.
0
John Davis
Top achievements
Rank 2
answered on 26 Nov 2009, 11:55 AM
It works! Thank you.
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
John Davis
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or