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

Gridview selected cell to textbox :]

3 Answers 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
eric
Top achievements
Rank 1
eric asked on 13 Dec 2010, 11:49 PM
Just wanted to state i think these controls are great!! just having a little trouble adapting.

This is what im trying to do.

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)   
{         
  
this.TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
}

but using the new radgrid its different. can someone help? thanks!


-EricPacheco

3 Answers, 1 is accepted

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

The following code snippet shows how to achieve this.

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
   {
       this.TextBox1.Text = RadGrid1.SelectedItems[0].Cells[2].Text;
                       //or
       GridDataItem item = (GridDataItem)RadGrid1.SelectedItems[0];
       TextBox1.Text = item["FirstName"].Text;//access cell value using 'ColumnUniqueName'
    }

Note: You must set EnablePostBackOnRowClick property of ClientSettings as "true" to fire this SelectedIndexChanged event.
<ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
</ClientSettings>

Thanks,
Princy.
0
eric
Top achievements
Rank 1
answered on 14 Dec 2010, 03:48 PM

 

protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)

 

{

RadTextBox1.Text = RadGrid1.SelectedItems[0].Cells[2].Text;

}

 

 

When I do select a row or any row, it fills the radtextbox with   &nbsp;  which im not sure why...
Any suggestions?

UPDATE:
Okay i figured it out. for some reason it starts the column at [2] and my data didnt start till [4].
Thanks!

0
Veli
Telerik team
answered on 14 Dec 2010, 04:26 PM
Hello eric,

The first 2 cells in every grid data item are reserved for 2 service columns in RadGrid that are always initialized. So the first visible data cell in the grid starts from index 2.

Greetings,
Veli
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
eric
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
eric
Top achievements
Rank 1
Veli
Telerik team
Share this question
or