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

Get current datasource item in javascript

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
plusHR
Top achievements
Rank 1
plusHR asked on 12 Apr 2012, 03:55 PM
Hi all.

I am binding my RadGrid to an EntityDataSource. When the user clicks a row I want to retrieve the current data item and get the values from it. Could someone point me in the right direction. I am assuming that as the table is data bound, when selecting a row the data can be made available in Javascript? Thus the entity has 5 columns, 2 of these are shown as columns in the grid.

Thanks
P

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 16 Apr 2012, 04:47 PM
Paul:

If I understand you're requirement, this should help. It attaches the function RowClick(sender, eventArgs) to <ClientEvents OnRowClick="RowClick" /> and displays the value of the cell in column 2 (columns are 0-based).

function RowClick(sender, eventArgs) {
    //alert("Click on row instance: " + eventArgs.get_itemIndexHierarchical());
    var row = sender.get_masterTableView().get_dataItems()[eventArgs.get_itemIndexHierarchical()].get_element();
    var title = row.cells[1].innerHTML;
    confirm('The value of the cell in column 2: ' + title); // columns are 0-based
}

<ClientSettings EnablePostBackOnRowClick="false">
    <ClientEvents OnRowClick="RowClick" />
    <Selecting AllowRowSelect="true" />
</ClientSettings>

See attached image.

Hope this helps.
Tags
Grid
Asked by
plusHR
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or