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

Auto select the first row in the datagrid

4 Answers 683 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lamborghini
Top achievements
Rank 1
Lamborghini asked on 13 Dec 2010, 11:15 PM
Hi All,

This seems to be a simple question. I need to autoselect the first row in the data grid after the rebind() function. Here is the section of the RadGrid

<

 

 

ClientSettings>

 

 

 

<ClientEvents OnRowDblClick="DataGridRowDblClicked" />

 

 

 

<Scrolling AllowScroll="true" ScrollHeight="235px" />

 

 

 

<Selecting AllowRowSelect="true" />

 

 

 

</ClientSettings>
Thanks,
E.

 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Dec 2010, 06:05 AM
Hello,

You can set the Selected property to true for  the first row  like below.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
  {
      RadGrid1.MasterTableView.Items[0].Selected = true;
  }

Thanks,
Princy.
0
Lamborghini
Top achievements
Rank 1
answered on 14 Dec 2010, 02:33 PM
Thank you for the reply.
I should have been more clear. I need to do this client side.

Thanks,
E.
0
Lamborghini
Top achievements
Rank 1
answered on 14 Dec 2010, 03:09 PM
In addition to my earlier comment, this RadGrid is located in a tab which is not visible by default. Therefore, The databinding is delayed until the tab is selected. Hence the server code that was provided would not work since I could not tell whether the RadGrid was in its initial dataload or not.

Thanks,
E.
0
Marin
Telerik team
answered on 17 Dec 2010, 05:45 PM
Hello Ernesto,

You can select the first row of the grid client-side in the following way after the grid is rebound:
var grid = $find("<%= RadGrid1.ClientID %>");
                if (grid.get_masterTableView()!= null && grid.get_masterTableView().get_dataItems().length>0) {
                    grid.get_masterTableView().get_dataItems()[0].set_selected();
                }
or you can add the index of the first item to the selectedIndexes collection for the grid in server side.
RadGrid1.SelectedIndexes.Add(0);

Let me know how this works for you and if you have other questions.

Best wishes,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Lamborghini
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lamborghini
Top achievements
Rank 1
Marin
Telerik team
Share this question
or