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

selecting radgrid row and displaying values in textboxes

9 Answers 415 Views
Grid
This is a migrated thread and some comments may be shown as answers.
yogesh
Top achievements
Rank 1
yogesh asked on 27 Feb 2011, 07:12 AM
Hi,
    I am yogesh. I am new to asp.net with c# and working on telerik asp.netajax radgrid control. i want to select a row from radgrid and need to display values of row in textboxes which are in the same page.Could anyone help me out plz...

9 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 28 Feb 2011, 05:55 AM
Hello Yogesh,

Check out the following sample code snippet which shows how to achieve this. You can get the selected row and cell value in 'OnSelectedIndexChanged' event of RadGrid and then populate the TextBox(outside grid) with these values.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="EmployeeID" UniqueName="EmployeeID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
    </ClientSettings>
</telerik:RadGrid>
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
   {
       GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];//accessing selected row
       string value = selectedItem["FirstName"].Text;//getting cell value
       TextBox1.Text = value;
   }

Note: You need to set 'EnablePostBackOnRowClick="true" to fire 'OnSelectedIndexChanged' od RadGrid.

Thanks,
Princy.
0
yogesh
Top achievements
Rank 1
answered on 28 Feb 2011, 06:37 AM
Thanks a lot princy.....its working for me with your code snippet....great work from you.




Regards,
Yogesh
0
Ram
Top achievements
Rank 1
answered on 30 Jun 2011, 08:39 AM
Hi
EnablePostBackOnRowClick="true"  property is not showing in radgrid.
How can I set this property.
0
Princy
Top achievements
Rank 1
answered on 30 Jun 2011, 08:45 AM
Hello Ram,

Try setting EnablePostBackOnRowClick in ClientSettings as shown below.

aspx:
<ClientSettings EnablePostBackOnRowClick="true" >
</ClientSettings>

Thanks,
Princy.
0
Chigicherla
Top achievements
Rank 1
answered on 23 Jul 2013, 07:14 PM
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
   {
       GridDataItem selectedItem = (GridDataItem)RadGrid1.SelectedItems[0];//accessing selected row
       string value = selectedItem["FirstName"].Text;//getting cell value
       TextBox1.Text = value;
   }

The GridDataItem is not getting for me in Radgrid..

Could you plz help me any thing else to be added in anywhere.....
0
Shinu
Top achievements
Rank 1
answered on 26 Jul 2013, 09:50 AM
Hi ,

I tried to replicate the issue but no avail,can you please try the following code snippet.If this doesn't help,please provide your full code,with your desired requirements.

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridDataItem item in RadGrid1.SelectedItems)
  {
 foreach (GridColumn column in item.OwnerTableView.Columns)
  {
  Response.Write(String.Format("{0} : {1} <br />", column.UniqueName, item[column.UniqueName].Text));//Accessing Column Name,Column Value
  }
}
}

Thanks,
Shinu
0
Jaakko
Top achievements
Rank 1
answered on 27 Dec 2013, 07:41 AM
GridDataItem seems to be a part of telerik.web.ui - had to figure that one out too.
0
Muhammad
Top achievements
Rank 1
answered on 15 Mar 2016, 04:28 PM

Thanks much Princy,

I used your code and it works!

There is something worth mentioning though, at least for novice users like myself, I needed to replace "GridDataItem" with "Telerik.Web.UI.GridDataItem".

Also needed to reference this RadGrid1_SelectedIndexChanged in my RadGrid's Properties events, under "SelectedIndexChanged"

0
Anil
Top achievements
Rank 1
answered on 14 Nov 2017, 05:50 PM

Hi am using server side binding i need to populate values to control outise grid on clicking edit in radgrid(server side)

 

Tags
Grid
Asked by
yogesh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
yogesh
Top achievements
Rank 1
Ram
Top achievements
Rank 1
Chigicherla
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Jaakko
Top achievements
Rank 1
Muhammad
Top achievements
Rank 1
Anil
Top achievements
Rank 1
Share this question
or