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

extracting data key value on client side

3 Answers 371 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 14 Feb 2009, 02:35 AM

i have a link inside the gridtemplatecolumn of a grid.

on click of that link i call a js function.
I need to know the DataKey value of that row in which the link was clicked in the javascript function.

How can i get the key value on client side.
I was trying to do something like :

 

var

masterTable = $find("<%=RadGridContact.ClientID%>").get_masterTableView();

 

 

var contactId = masterTable.get_selectedItems()[0].getDataKeyValue("ContactID");

But the problem is that my row is not selected so i get the selecetedItems as null.

can you suggest?

 

3 Answers, 1 is accepted

Sort by
0
Steve Y
Top achievements
Rank 2
answered on 15 Feb 2009, 01:08 AM
In order to be able to get access to the data keys client side, you need to declare them in the grid MasterTableView ClientdataKeyNames declaration something like this:

<MasterTableView AutoGenerateColumns="False" DataKeyNames="PropertyId" ClientDataKeyNames="PropertyId,Address"  
            DataSourceID="LinqDS_Properties" EditMode="PopUp" CommandItemDisplay="Top" InsertItemDisplay="top"  
            GridLines="None"

Then you can access them in javascript on the client something like this:

function RowDblClick(sender, args) { 
        var index = args.get_itemIndexHierarchical(); 
        var tableView = args.get_tableView(); 
        var dataItems = tableView.get_dataItems(); 
        var dataItem = dataItems[index]; 
        var propertyId = dataItem.getDataKeyValue("PropertyId"); 
        var address = dataItem.getDataKeyValue("Address");         
    } 

Hope this helps,

Steve


0
newbie
Top achievements
Rank 1
answered on 15 Feb 2009, 06:28 AM

I am not double clicking the row.

I want to find the row index when i click a hyperlink in one of the rows.

 

Thanks in advance.

0
Steve Y
Top achievements
Rank 2
answered on 15 Feb 2009, 12:20 PM
Checkout this example for how to attach a javascript call with the datakey of the clicked row to see if it helps.

http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid

Regards, Steve



Tags
Grid
Asked by
newbie
Top achievements
Rank 1
Answers by
Steve Y
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Share this question
or