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

Itemcommand DataKeyValue on RowDoubleClick

2 Answers 28 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 12 May 2014, 04:01 PM
Hi,

I am trying to fire the itemcommand server event on RowDoubleClick client event. 

Javascript
function RowDblClick(sender, eventArgs) {
      var dataKeyVal = eventArgs.getDataKeyValue("UserName")
      sender.get_masterTableView().fireCommand("EditUser", dataKeyVal);
}

Code Behind
if (e.CommandName == "EditUser")
{
    GridDataItem item = e.Item as GridDataItem;
    item.Selected = true;
    string uName = item.GetDataKeyValue("UserName").ToString();
}

This gets me the DataKeyValue no problem in Javascript and runs the ItemCommand, but when the ItemCommand fires in the code behind it is acting on the first row in the grid rather than the double clicked row.

How would I have the ItemCommand run on the row that was doubleclicked?

Thanks,
Marc

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 13 May 2014, 05:30 AM
Hi Marc,

Please try the following code snippet to get the double-clicked row on ItemCommand event.

JS:
function RowDblClick(sender, eventArgs) {
    var grid = $find("<%=RadGrid1.ClientID %>");
    var master = grid.get_masterTableView();
    selectedRow = eventArgs.get_itemIndexHierarchical();
    master.fireCommand("EditUser", selectedRow);
}

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
   if (e.CommandName == "EditUser")
   {
     GridDataItem item = RadGrid1.Items[e.CommandArgument.ToString()];
     item.Selected = true;
     string userName= item.GetDataKeyValue("UserName").ToString();     
   }
}

Thanks,
Princy
0
Marc
Top achievements
Rank 1
answered on 13 May 2014, 08:02 AM
Thank you Princy, this has solved my issue.
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Marc
Top achievements
Rank 1
Share this question
or