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

Get the DataKeyValues of the selected item in js

1 Answer 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jing
Top achievements
Rank 1
jing asked on 13 Aug 2010, 10:57 AM
Hi,

1) How do I get the DataKeyValues (ID) of the selected item?

<telerik:RadGrid ID="GridDocument" runat="server">
<MasterTableView DataKeyNames="ID">
    <Columns>
        ...
    </Columns>
</MasterTableView>
<ClientSettings>
    <Selecting AllowRowSelect="True"></Selecting>
</ClientSettings>
</telerik:RadGrid>

2) Is there a url that I can refer to the Client Object API?

Thanks in advance.

Jing

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 13 Aug 2010, 11:54 AM
Hello Jing,

In order to access the DataKeyValue from client side, add the value of the DateField to the ClientDataKeyNames array of the MasterTableView . Check out the following client code which access the DataKeyValue of the selected row from an external event such as button click.

ASPX:
<telerik:RadGrid ID="GridDocument" runat="server">
<MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID">
    <Columns>
        ...
    </Columns>
</MasterTableView>
<ClientSettings>
    <Selecting AllowRowSelect="True"></Selecting>
</ClientSettings>
</telerik:RadGrid>
 
<asp:Button ID="Button4" runat="server" OnClientClick="OnClientClick();" Text="Button" />

Java Script:
<script type="text/javascript">
  function OnClientClick() {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var MasterTable = grid.get_masterTableView();
        if(MasterTable.get_selectedItems().length>0)
        var dataKeyValue = MasterTable.get_selectedItems()[0].getDataKeyValue("ID"); // get the DataKeyValue of selected item
    }
</script>

Also please refer the following documentation.
Extracting key values client-side

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