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

Accessing Selected Grid Cell Value on Client Side

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 28 Jul 2011, 12:45 AM
I have the following simple javascript function that fires when the user clicks OK in a RadConfirm window.  The function should return the DataKeyValue for the selected row.  However it currently returns null and I can figure out why.  Can someone please tell me what my mistake was?

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
    function confirmCallBackFn(arg) {
        if (arg == true) {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        var selectedRows = MasterTable.get_selectedItems();
        for (var i = 0; i < selectedRows.length; i++) {
            var row = selectedRows[i];
            var PackageID = MasterTable.getCellByColumnUniqueName(row, "PackageID")
            alert(PackageID);
        }
 
        }
        else {
        }
    }
</script>
 
</telerik:RadCodeBlock>


Below is the relevant portion of my RadGrid1 code.  My DataKeyName and Column Unique Name are both "PackageID" as required by the JavaScript function.
<MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource2" DataKeyNames="PackageID, Status">
                       <CommandItemSettings ExportToPdfText="Export to PDF" />
                       <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                       </RowIndicatorColumn>
                       <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                       </ExpandCollapseColumn>
                       <Columns>
                           <telerik:GridBoundColumn DataField="PackageID"
                               FilterControlAltText="Filter PackageID column" HeaderText="PackageID"
                               SortExpression="PackageID" UniqueName="PackageID" DataType="System.Int32"
                               ReadOnly="True" Visible="false">

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Jul 2011, 06:06 AM
Hello Daniel,

Since you are setting the visibilty of BoundColumn as false, you can access the DataKeyNames by setting ClientDataKeyNames. Try the following code snippet to access the DataKeyNames.

aspx:
<MasterTableView DataKeyNames="PackageID" ClientDataKeyNames="PackageID" CommandItemDisplay="Top">
</MasterTableView>

Javascript:
function confirmCallBackFn(arg)
{
         . . .
    var key=args.getDataKeyValue("PackageID");
       alert(key);
}

Thanks,
Princy.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or