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

[Solved] OnRowSelect : how to get the selected item id?

1 Answer 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Julien
Top achievements
Rank 1
Julien asked on 16 Mar 2012, 10:28 AM
Hi,

I'm using the grid with the selectable property, so I had to specify the DataKeys:

.DataKeys(keys=>{
    keys.Add(c => c.Id);
 })

But I can't find any way to get this key when I receive the row selected event in javascript. How should I do this???

Thank you

1 Answer, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 16 Mar 2012, 05:43 PM
if i'm not wrong, the DataKey is need only in server side binding, it's not transmit in the client event.But you probably could find the Id by a jquery selector with the row .(look here)

<script type="text/javascript">
function Grid_onRowSelect(e) {
    // get the DOM element which represents the clicked row
    var row = e.row;
    // get the instance of the grid client-side object
    var grid = $(this).data("tGrid");
    // use the dataItem method of the grid to get the data item to which the row is bound to
    var dataItem = grid.dataItem(row);

    var id = dataItem.Id;
}
</script>
Tags
Grid
Asked by
Julien
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Share this question
or