Get cell value of selected row in grid using getCellByColumnUniqueName?

3 posts, 0 answers
  1. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 23 Oct 2018 Link to this post

    I'm attempting to get the value of a cell in a selected row of a grid, and populate a textbox with it.  I'm using the example from the Telerik documentation, so most likely I'm failing to properly assign the value from the cell to the textbox.

    Grid and textbox markup:

    <telerik:RadGrid runat="server" ID="rgAdList" DataSourceID="sdsRgAdList" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" ShowGroupPanel="True" OnSelectedIndexChanged="rgAdList_OnSelectedIndexChanged">
            <ClientSettings AllowDragToGroup="True" AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                <Selecting AllowRowSelect="True"></Selecting>
                <ClientEvents OnRowSelected="RowSelected"></ClientEvents>
            </ClientSettings>
            <MasterTableView DataKeyNames="mail" DataSourceID="sdsRgAdList">
                <Columns>
                    <telerik:GridBoundColumn DataField="givenName" HeaderText="First Name" SortExpression="givenName" UniqueName="givenName" FilterControlAltText="Filter givenName column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="sn" HeaderText="Last Name" SortExpression="sn" UniqueName="sn" FilterControlAltText="Filter sn column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="mail" ReadOnly="True" HeaderText="Email" SortExpression="mail" UniqueName="mail" FilterControlAltText="Filter mail column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="department" HeaderText="Department" SortExpression="department" UniqueName="department" FilterControlAltText="Filter department column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="manager" HeaderText="Manager" SortExpression="manager" UniqueName="manager" FilterControlAltText="Filter manager column" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
         
        <br/><br/>
        <asp:TextBox runat="server" ID="mgrtxt"></asp:TextBox>

     

    Here is the js:

    <script type="text/javascript">
        function RowSelected(sender, eventArgs) {
            var grid = sender;
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
            var cell = MasterTable.getCellByColumnUniqueName(row, "manager").innerHTML;
            var mgrval = document.getElementById('<%= mgrtxt.ClientID %>');
            mgrval.Text = cell;
        };
    </script>

     

    How can I get the value of the selected row in the "manager" column into the "mgrtxt" textbox?

  2. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 23 Oct 2018 in reply to Jerald Link to this post

    I tried this as well, and I still get "undefined" in the textbox.

    <script type="text/javascript">
        function RowSelected() {
            var masterTable = $find("<%=rgAdList.ClientID%>").get_masterTableView();
            var mgrcell = masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[0], "manager").innerHTML;
            var mgrval = document.getElementById('<%= mgrtxt.ClientID %>');
            mgrval.value = mgrcell.value;
        };
    </script>
  3. Jerald
    Jerald avatar
    32 posts
    Member since:
    Jan 2016

    Posted 24 Oct 2018 in reply to Jerald Link to this post

    OK, changed Text to value and it works.  

    <script type="text/javascript">
        function RowSelected(sender, eventArgs) {
            var grid = sender;
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
            var cell = MasterTable.getCellByColumnUniqueName(row, "manager").innerHTML;
            var mgrval = document.getElementById('<%= mgrtxt.ClientID %>');
            console.log("this is the value of cell ... " + cell);
     
            mgrval.value = cell;
        };
    </script>
Back to Top