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

GetDataKeyValue is null in server RowDrop event when items are bound client side

1 Answer 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 19 Mar 2009, 05:24 PM
I have a grid which is populated client side, using a web service. As per the examples I use the tableView.set_dataSource property and the dataBind() method.

When I use Drag and Drop on a row to in the grid, the event handler on the server side for RodDrop fires, but the GetDataKeyValue method returns null for both destination and dragged items.  (This value is available client side).

From reading others forum articles it appears that the GetDataKeyValue would only work if the grid was populated Server Side since it is stored in view state.

If this is the case is there a workaround? 

1 Answer, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 20 Mar 2009, 10:23 AM
I have managed to find a solution:

On the client I capture the RowDropping event and then extract the values of each row (NOTE: I am only allowing a single row select).  Having extracted the values I use the fireCommand to create a new command with a custom Name e.g. CustomRowDrop

 
        function RadGrid1_RowDropping(sender, args)  
        {  
            args.set_cancel(true);  
            var targetId = args.get_targetGridDataItem().get_dataItem().DataValueLinkId;  
            var destId = args.get_draggedItems()[0].get_dataItem().DataValueLinkId;  
 
            $find("<%= RadGrid1.ClientID %>").get_masterTableView().fireCommand("CustomRowDrop", targetId + "," + destId);  
 
        }  

In my RadGrid defintion I define an event handler for OnItemCommand event:
   <telerik:RadGrid ID="RadGrid1"  runat="server"   
     Skin="Office2007"   
     OnItemCommand="RadGrid1_ItemCommand" 
     > 
     ...</telerik:RadGrid > 
 

Finally in the ItemCommand event handler I check for my custom command, parse the values and call my custom sort routine:
        void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
        {  
            if (e.CommandName == "CustomRowDrop")  
            {  
                string[] ids = e.CommandArgument.ToString().Split(',');  
 
                RadGrid1_CustomRowDrop(int.Parse(ids[0]), int.Parse(ids[1]));  
            }  
        } 



Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Share this question
or