Get the value of a Cell in a RadGrid and pass it to a RadTextBox using the Client Event OnRowSelected

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

    Posted 02 May 2012 Link to this post

    I have a question, how i can Get the value of a Cell in a RadGrid and pass it to a RadTextBox using the Client Event "OnRowSelected"??

    thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 May 2012 Link to this post

    Hello Joswhar,

    Try the following javascript to show selected value in RadTextBox.
    JS:
    function OnRowSelected(sender, args)
    {
     var masterTable = sender.get_masterTableView();
     var selectedrow = masterTable.get_selectedItems();
     for (var i = 0; i < selectedrow.length; i++)
     {
      var cell = masterTable.getCellByColumnUniqueName(selectedrow[i], "UniqueName");
      var txt = selectedrow[i].findControl('RadTextBox1');
      txt.set_value(cell.innerHTML);
     }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 02 May 2012 Link to this post

    Thanks for your answer Shinu,

    I get the following error:
    Error: Unable to get value of the property 'set_value': object is null or undefined
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 May 2012 Link to this post

    Hello Joswhar,

    This error means that "txt" is null at the client side. Please make sure that you have not set Visible property as false for the RadTextBox. Please provide your code for further assistance.

    Thanks,
    Shinu.
  6. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 02 May 2012 Link to this post

    Hi Shinu, really appreciate your help, thanks

    this is the code complete that i used:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
     
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">           
     
                function OnRowSelected(sender, args)
                {
                    var masterTable = sender.get_masterTableView();
                    var selectedrow = masterTable.get_selectedItems();
                    for (var i = 0; i < selectedrow.length; i++)
                    {
                        var cell = masterTable.getCellByColumnUniqueName(selectedrow[i], "IDOcurrencia");
                        var txt = selectedrow[i].findControl('txt1');
                        txt.set_value(cell.innerHTML);
                    }
                }
     
    </script>
    </telerik:RadCodeBlock>
        
    </head>
    <body>
         
    <form runat="server" id="mainForm" method="post">
           
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
            <!-- content start -->
            <telerik:RadAjaxManager ID="RadAjaxManager" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid2">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid2" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
           
            <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" GridLines="None"
                ShowStatusBar="True" AllowPaging="True" Width="97%"
                runat="server" CellSpacing="0" >
                <MasterTableView Width="100%" ClientDataKeyNames="IDOCURRENCIA,FECHA" >
    <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
     
    <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
     
    <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
     
    <EditFormSettings>
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />
                    <ClientEvents OnRowSelected="OnRowSelected" />
                </ClientSettings>
     
    <FilterMenu EnableImageSprites="False">
    <WebServiceSettings>
    <ODataSettings InitialContainerName=""></ODataSettings>
    </WebServiceSettings>
    </FilterMenu>
     
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
    <WebServiceSettings>
    <ODataSettings InitialContainerName=""></ODataSettings>
    </WebServiceSettings>
    </HeaderContextMenu>
            </telerik:RadGrid>
            <br />
            <br />
            <asp:Label ID="Label1" runat="server"></asp:Label>
            <br />
             <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="Data Source=SERVER2008;Initial Catalog=MicroAdminGOC;Persist Security Info=True;User ID=sa;Password=xxx"
                ProviderName="System.Data.SqlClient"
                SelectCommand="SELECT IDOcurrencia,Fecha,Status  FROM log_mensaje"
                runat="server"></asp:SqlDataSource>
            <br />
     
    <telerik:RadTextBox ID="txt1" runat="server">
    </telerik:RadTextBox>
     
            <!-- content end -->
           
        </form>
    </body>
     
    </html>
  7. Joswhar
    Joswhar avatar
    11 posts
    Member since:
    Apr 2012

    Posted 02 May 2012 Link to this post

    Hello Shinu,

    finally I did, I changed only one line of code
    Annex the final code:
    js
    function OnRowSelected(sender, args)
    {
     var masterTable = sender.get_masterTableView();
     var selectedrow = masterTable.get_selectedItems();
     for (var i = 0; i < selectedrow.length; i++)
     {
      var cell = masterTable.getCellByColumnUniqueName(selectedrow[i], "UniqueName");
      var txt = $find("<%= RadTextBox1.ClientID %>")
      txt.set_value(cell.innerHTML);
     }
    }

    Thank you very much for your help
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017