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

12 posts, 0 answers
  1. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 27 Apr 2012 Link to this post

    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.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Apr 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 27 Apr 2012 Link to this post

    Thanks Princy, as would be the code in visual basic.net 2010?
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Apr 2012 Link to this post

    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.
  6. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 27 Apr 2012 Link to this post

    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
  7. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 27 Apr 2012 Link to this post

    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.
  8. Chigicherla
    Chigicherla avatar
    2 posts
    Member since:
    Jul 2013

    Posted 23 Jul 2013 Link to this post


    GridData Item  is not getting for me in RadGrid.

    Can anyone help me please
  9. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 26 Jul 2013 Link to this post

    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.
  10. RAVI SHARMA
    RAVI SHARMA avatar
    9 posts
    Member since:
    Oct 2013

    Posted 14 Feb 2014 in reply to Chigicherla Link to this post

    hey chigicherla have you any solution as get selected row value in text box . please tell me what i do..............
  11. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 19 Feb 2014 Link to this post

    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.
  12. Nitin
    Nitin avatar
    3 posts
    Member since:
    May 2015

    Posted 08 Sep 2015 in reply to Princy Link to this post

    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>​

  13. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 10 Sep 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017