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

1st row selected on page load?

2 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Megan
Top achievements
Rank 1
Megan asked on 25 Feb 2009, 03:26 PM

In the SelectedIndexChanged event of my page I use code to grab information the selected row, store it in a session and present the data in textboxes below the grid:

  

 

For Each item As GridDataItem In MyGrid.SelectedItems

    Dim sCode As String = Trim(item("sCode").Text.ToString())
    Session("sCode") = sValidationId
Next

 

 

txtCode.Text = Session("sCode")
 

 

I'd like to be able to have the first set of data already loaded into the textboxes once the page is loaded, so the user does not need to make a selection to fill the textboxes on load.

As the title states, how can I have the first row of my grid already selected when the page loads?

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 26 Feb 2009, 05:16 AM
Hi Megan,

Try the following code snippet in the Prerender event of the Grid.

CS:
   protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        //to set the first row of the Grid Selected on page load 
        if (!IsPostBack) 
            RadGrid1.MasterTableView.Items[0].Selected = true
 
        //to populate the TextBox with selected row's cell value 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
            TextBox1.Text = item["columnUniqueName"].Text; 
        } 
      
    } 


Thanks
Shinu
0
Megan
Top achievements
Rank 1
answered on 26 Feb 2009, 09:03 AM
Thanks very much, that worked fine. Marked as answer.
Tags
Grid
Asked by
Megan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Megan
Top achievements
Rank 1
Share this question
or