Select first row and pass ID (VB)

5 posts, 0 answers
  1. Jack
    Jack avatar
    128 posts
    Member since:
    May 2003

    Posted 11 Apr 2009 Link to this post

    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


  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 13 Apr 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 25 Nov 2009 Link to this post

    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

  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 25 Nov 2009 Link to this post

    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.
  6. John Davis
    John Davis avatar
    119 posts
    Member since:
    Apr 2007

    Posted 26 Nov 2009 Link to this post

    It works! Thank you.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017