RadGrid Drag and Drop Functionality

2 posts, 0 answers
  1. Monika
    Monika avatar
    9 posts
    Member since:
    May 2009

    Posted 09 Jun 2009 Link to this post

    Hello Telerik

    I have implement Drag and drop functionality in my page usign RadGrid. But I am not able to achieve this functionality.
    I have taken reference of telerik Demo application 

    But in this demo also reordring of grid rows is not working. Only movement of rows between within two grid is working 

       .aspx page code



    radControls:RadScriptBlock runat="server" ID="scriptBlock">



    <script type="text/javascript">



    function onRowDropping(sender, args)




    if (sender.get_id() == "<%=grdFieldValueList.ClientID %>")




    var node = args.get_destinationHtmlElement();



    if(!isChildOf('<%=grdFieldValueList.ClientID %>', node) )











    function isChildOf(parentId, element)








    if (element.id && element.id.indexOf(parentId) > -1)




    return true;



    element = element.parentNode;



    return false;







    <radControls:RadGrid ID="grdFieldValueList" runat=server AutoGenerateColumns=false OnRowDrop="grdFieldValueList_RowDrop">


    <ClientSettings AllowRowsDragDrop=true >



    <Selecting AllowRowSelect="True" EnableDragToSelectRows="true"/>



    <ClientEvents OnRowDropping="onRowDropping" />



    <Scrolling AllowScroll="true" UseStaticHeaders="true" />






    <MasterTableView DataKeyNames="FieldCode" GridLines="Both" BackColor="White">







    <radControls:GridBoundColumn DataField="FieldCode"></radControls:GridBoundColumn>



    <radControls:GridBoundColumn DataField="DisplayName"></radControls:GridBoundColumn>







    </MasterTableView >






    aspx.cs page code


    private static DWField GetFieldValue(IList<DWField> valuesToSearchIn, int FieldCode)




    foreach (DWField fieldValue in valuesToSearchIn)




    if (fieldValue.FieldCode == FieldCode)




    return fieldValue;





    return null;





    protected void grdFieldValueList_RowDrop(object sender, GridDragDropEventArgs e)




    if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdFieldValueList.ClientID)




    //reorder items in grid



    IList<DWField> fieldValueList = (IList<DWField>)Session["FieldList"];



    DWField tmpFieldValue = GetFieldValue(fieldValueList, (int)e.DestDataItem.GetDataKeyValue("FieldCode"));



    int destinationIndex = fieldValueList.IndexOf(tmpFieldValue);



    if (e.DropPosition == GridItemDropPosition.Above && e.DestDataItem.ItemIndex > e.DraggedItems[0].ItemIndex)



    destinationIndex -= 1;



    if (e.DropPosition == GridItemDropPosition.Below && e.DestDataItem.ItemIndex < e.DraggedItems[0].ItemIndex)



    destinationIndex += 1;



    List<DWField> ValuesToMove = new List<DWField>();



    foreach (GridDataItem draggedItem in e.DraggedItems)




    DWField tmpOrder = GetFieldValue(fieldValueList, (int)draggedItem.GetDataKeyValue("FieldCode"));



    if (tmpOrder != null)





    foreach (DWField dwField in ValuesToMove)




    fieldValueList.Insert(destinationIndex, dwField);




    "FieldValueList"] = fieldValueList;


    grdFieldValueList.DataSource = fieldValueList;





    e.DestDataItem.Selected =





    The problem is that RowDrop(Serevr side event is getting not fired  every time. It is getting fired sometimes and I am not able to find in which scenario it is getting fired .

    Kindly provide me the resolution of this problem

     Monika Sharma
  2. Bruno
    Bruno avatar
    105 posts
    Member since:
    Mar 2008

    Posted 12 Jun 2009 Link to this post

    Strange but for me the example is running as expected. In the left grid you can reorder items and drag it to right grid. From the right grid you can drag items to the trash can.

Back to Top