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

Get the value of a Cell in a RadGrid and pass it to a RadTextBox selecting the RadGrid Row

11 Answers 687 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Joswhar
Top achievements
Rank 2
Joswhar asked on 27 Apr 2012, 12:34 PM
Hello, i have a question. How I can get the value of a Cell in a RadGrid and pass it to a RadTextBox selecting the RadGrid Row?
Thank you.

11 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Apr 2012, 01:11 PM
Hello Joswhar,

Try the following code to set the selected value in RadTextBox.
aspx:
protected void grid_SelectedIndexChanged(object sender, EventArgs e)
{
    foreach (GridDataItem item in grid.SelectedItems)
   {
      string value = item["UniqueName"].Text;
      RadTextBox txt = (RadTextBox)item.FindControl("RadTextBox1");
      txt.Text = value;
   }
}
Note:Set ClientSettings -EnablePostBackOnRowClick as true.

Thanks,
Princy.
0
Joswhar
Top achievements
Rank 2
answered on 27 Apr 2012, 01:46 PM
Thanks Princy, as would be the code in visual basic.net 2010?
0
Princy
Top achievements
Rank 2
answered on 27 Apr 2012, 01:58 PM
Hello,

Here is the code in VB.
VB:
Protected Sub grid_SelectedIndexChanged(sender As Object, e As EventArgs)
    For Each item As GridDataItem In grid.SelectedItems
        Dim value As String = item("UniqueName").Text
        Dim txt As RadTextBox = DirectCast(item.FindControl("RadTextBox1"), RadTextBox)
        txt.Text = value
    Next
End Sub
Here is the link for converter.

Thanks,
Princy.
0
Joswhar
Top achievements
Rank 2
answered on 27 Apr 2012, 03:16 PM
I fail to work well, to obtain the desired information on a label use this function:
function RowSelected(sender, args) {
               document.getElementById("<%= Label1.ClientID %>").innerHTML =
                "<b>CustomerID: </b>" + args.getDataKeyValue("IDOCURRENCIA") +
                "<br />" +
                "<b>CompanyName: </b>" + args.getDataKeyValue("FECHA");
 
             }

but i dont know how to apply it to the RadTextbox.

thanks a lot Princy
0
Joswhar
Top achievements
Rank 2
answered on 27 Apr 2012, 04:27 PM
It's working now!!
I just made few small changes to the code and works very well, annex, Annex functional code:
Protected Sub RadGrid1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged
 
        For Each item As GridDataItem In RadGrid1.SelectedItems
            Dim value As String = item("UniqueName").Text
            RadTextBox1.Text = value
        Next
 
    End Sub

Thanks Princy, your support was invaluable.
Regards.
0
Chigicherla
Top achievements
Rank 1
answered on 23 Jul 2013, 07:08 PM

GridData Item  is not getting for me in RadGrid.

Can anyone help me please
0
Eyup
Telerik team
answered on 26 Jul 2013, 10:11 AM
Hi Chigicherla,

I suggest that we continue on the following thread:
http://www.telerik.com/community/forums/aspnet-ajax/grid/selecting-radgrid-row-and-displaying-values-in-textboxes.aspx

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Ravi
Top achievements
Rank 1
answered on 14 Feb 2014, 03:29 PM
hey chigicherla have you any solution as get selected row value in text box . please tell me what i do..............
0
Eyup
Telerik team
answered on 19 Feb 2014, 11:43 AM
Hi Ravi,

Can you please elaborate on your specific scenario?
Generally, you can check this article for accessing grid cell values:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Nitin
Top achievements
Rank 1
answered on 08 Sep 2015, 09:15 AM

I am doing the same. But i am not getting postback on Row click to access the cell items.

Below is the code snippet.

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"
                                    OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="False" GroupPanelPosition="Top"
                                    Height="255px" Width="1320px" OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"
                                    OnItemCommand="RadGrid1_ItemCommand" OnItemEvent="RadGrid1_ItemEvent">
                                    <ClientSettings EnablePostBackOnRowClick="True">
                                        <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true" FrozenColumnsCount="2">
                                        </Scrolling>
                                    </ClientSettings>
                                    <MasterTableView AutoGenerateColumns="false" ShowFooter="True">
                                        <Columns>
                                            <telerik:GridHyperLinkColumn DataTextField="abc" UniqueName="abc" HeaderText="abc">
                                                <HeaderStyle CssClass="RadGridColumnHeader" HorizontalAlign="Center" VerticalAlign="Middle" />
                                            </telerik:GridHyperLinkColumn>
                                            <telerik:GridButtonColumn DataTextField="def" HeaderText="def">
                                            </telerik:GridButtonColumn>
                                            <telerik:GridHyperLinkColumn DataTextField="ghi" HeaderText="ghi">
                                            </telerik:GridHyperLinkColumn>
                                                                                                                                                                                </Columns>
                                    </MasterTableView>
                                </telerik:RadGrid>​

0
Eyup
Telerik team
answered on 10 Sep 2015, 11:12 AM
Hello Nitin,

I can see that you've enabled the EnablePostBackOnRowClick property:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/client-side-programming/making-postback-or-ajax-request-on-client-row-click

This should cause a page postback on every row click. Could you temporarily disable any AJAX on the page(RadAjaxPanels, RadAjaxManager, UpdatePanel, etc.) and enable your script debugger (FireBug or F12) to see whether there are any script errors interfering.

You can also examine the RadGridGetAllSelectedItemsImproved.zip sample provided in the following post for a more advanced selection scenario:
http://www.telerik.com/support/code-library/get-selected-items-through-all-pages#1eTU8nr-GUG8zfGgOGbIcA


Hope this helps.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Ajax
Asked by
Joswhar
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Joswhar
Top achievements
Rank 2
Chigicherla
Top achievements
Rank 1
Eyup
Telerik team
Ravi
Top achievements
Rank 1
Nitin
Top achievements
Rank 1
Share this question
or