This is a migrated thread and some comments may be shown as answers.
Get cell value of selected row in grid using getCellByColumnUniqueName?
2 Answers 51 Views
This is a migrated thread and some comments may be shown as answers.
Jerald
Top achievements
Rank 1
Jerald asked on 23 Oct 2018, 08:36 PM

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 Answers, 1 is accepted

Sort by
0
Jerald
Top achievements
Rank 1
answered on 23 Oct 2018, 09:32 PM

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>
0
Jerald
Top achievements
Rank 1
answered on 24 Oct 2018, 09:18 PM

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>
Tags
Grid
Asked by
Jerald
Top achievements
Rank 1
Answers by
Jerald
Top achievements
Rank 1
Share this question
or