Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

Grid / Items Drag-and-drop

Select and drag orders from pending to shipped when dispatched
Reorder pending orders on priority by drag and drop
Drop a shipped order over the recycle bin to delete it

Pending Orders

Order IDCustomer IDCompanyDate
10248VINETVins et alcools Chevalier8/1/1996
10249TOMSPToms Spezialitäten8/16/1996
10250HANARHanari Carnes8/5/1996
10251VICTEVictuailles en stock8/5/1996
10252SUPRDSuprêmes délices8/6/1996
10253HANARHanari Carnes7/24/1996
10254CHOPSChop-suey Chinese8/8/1996
10255RICSURichter Supermarkt8/9/1996
10256WELLIWellington Importadora8/12/1996
10257HILAAHILARION-Abastos8/13/1996
10259CENTCCentro comercial Moctezuma8/15/1996
10260OTTIKOttilies Käseladen8/16/1996
10261QUEDEQue Delícia8/16/1996
10262RATTCRattlesnake Canyon Grocery8/19/1996
10263ERNSHErnst Handel8/20/1996
10264FOLKOFolk och fä HB8/21/1996
10265BLONPBlondesddsl père et fils8/22/1996
10266WARTHWartian Herkku9/6/1996
10267FRANKFrankenversand8/26/1996
10268GROSRGROSELLA-Restaurante8/27/1996
10269WHITCWhite Clover Markets8/14/1996
10271SPLIRSplit Rail Beer & Ale8/29/1996
10272RATTCRattlesnake Canyon Grocery8/30/1996
10273QUICKQUICK-Stop9/2/1996
10274VINETVins et alcools Chevalier9/3/1996
10276TORTUTortuga Restaurante8/22/1996
10277MORGKMorgenstern Gesundkost9/6/1996
10278BERGSBerglunds snabbköp9/9/1996
10279LEHMSLehmanns Marktstand9/10/1996
10280BERGSBerglunds snabbköp9/11/1996
 Page 1 of 24, items 1 to 30 of 707.

Shipped Orders

Order IDCustomer IDCompanyDate
No items to view

  • RadGrid exposes flexible event-driven mechanism to drag and drop grid records to reorder them within the same grid, move them to different grid instance or drop them over other html element on the page. In order to enable drag and drop of grid items, you need to set the two boolean grid properties to true, namely:

    <ClientSettings AllowRowsDragDrop="true">
       <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
    </ClientSettings>

    This will make the grid data rows draggable and the end user will be able to relocate them if needed.

    Additionally, you can use the GridDragDropColumn. When a GridDragDropColumn is defined in the Columns collection of a GridTableView, grid items can be grabbed only by the drag handle rendered in this column:

    <telerik:GridDragDropColumn HeaderStyle-Width="18px">
    </telerik:GridDragDropColumn>

    The event-driven model which allows you to process and complete the drag and drop operation can be separated into two phases: client-side and server-side phase.

    Client-side phase

    There are three client grid events exposed to handle drag/drop action: OnRowDragStarted (cancelable), OnRowDropping (cancelable) and OnRowDropped.

    • The OnRowDragStarted event can be intercepted if you want to perform some conditional check and determine whether to cancel the drag operation or not. The syntax of the event handler follows the general client-side event signature of RadGrid for ASP.NET AJAX. The row which is about to be dragged can be accessed through the get_gridDataItem() property of the second argument passed in the OnRowDragStarted handler.
    • The OnRowDropping event should be attached to identify the target element on which the dragged grid record is dropped. If this element does not meet your criteria for acceptable target, cancel the operation by setting args.set_cancel(true) where args is the second argument passed to the OnRowDropping handler. Additionally, to determine the destination element or set it explicitly use the get_destinationHtmlElement() and set_destinationHtmlElement() properties that can be accessed through the args argument in the handler. Again, the syntax of the event handler follows the general client-side event signature of RadGrid for ASP.NET AJAX.
    • The OnRowDropped event can be handled if you would like to execute some extra code logic prior to the server-side OnRowDrop event rising. This event cannot be cancelled and have the same set of arguments as the OnRowDropping client event.

    Server-side phase

    On the server there is a single event (named OnRowDrop). Subscribing to this event allows you to reorder the items in the source grid or remove them and append these rows to a destination grid instance. The sequence of actions you will have to undertake in order to change the source structure may vary because this depends strictly on the underlying data source and its data model. The common logic in all cases, however, is that you can use three arguments passed in the handler to accomplish the task:

    • e.HtmlElement - holds the html element (or grid item)
    • e.DestDataItem - the destination grid item object (either GridDataItem or GridNoRecordsItem)
    • e.DraggedItems - a collection of GridDataItems which holds the rows that are taking part in the current drop operation
    • e.DestinationGrid - a reference to the grid instance to which the row has been dragged to
    • e.DestinationTableView - a reference to the table to which the row has been draggged to, points to the MasterTableView or detail table in hierarchical grid

    Combining the client and server part completes the circle and separates logically each part of the drag and drop process until it is finalized. For richer end user experience you can ajaxify the grid via RadAjaxManager and use RadAjaxLoadingPanel indicators. Otherwise the drag and drop operation will be performed with plain postback.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" AutoEventWireup="false" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.GridExamplesCSharp.Programming.DragAndDrop.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <telerik:HeadTag ID="Headtag2" runat="server"></telerik:HeadTag>
        <link href="Common/example.css" rel="stylesheet" type="text/css" />
    </head>
    <body class="BODY">
        <form id="mainForm" method="post" runat="server">
        <telerik:Header ID="Header1" runat="server" NavigationLanguage="CS"></telerik:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <!-- content start -->
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
        <telerik:RadAjaxManager runat="server" ID="radAjax" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="grdPendingOrders">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grdPendingOrders" />
                        <telerik:AjaxUpdatedControl ControlID="grdShippedOrders" />
                        <telerik:AjaxUpdatedControl ControlID="msg" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="grdShippedOrders">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grdShippedOrders" />
                        <telerik:AjaxUpdatedControl ControlID="msg" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="UseDragColumnCheckBox">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="grdPendingOrders" />
                        <telerik:AjaxUpdatedControl ControlID="grdShippedOrders" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadScriptBlock runat="server" ID="scriptBlock">

            <script type="text/javascript">
                    <!--
                function onRowDropping(sender,args) {
                    if(sender.get_id()=="<%=grdPendingOrders.ClientID %>") {
                        var node=args.get_destinationHtmlElement();
                        if(!isChildOf('<%=grdShippedOrders.ClientID %>',node)&&!isChildOf('<%=grdPendingOrders.ClientID %>',node)) {
                            args.set_cancel(true);
                        }
                    }
                    else {
                        var node=args.get_destinationHtmlElement();
                        if(!isChildOf('trashCan',node)) {
                            args.set_cancel(true);
                        }
                        else {
                            if(confirm("Are you sure you want to delete this order?"))
                                args.set_destinationHtmlElement($get('trashCan'));
                            else
                                args.set_cancel(true);
                        }
                    }
                }

                function isChildOf(parentId,element) {
                    while(element) {
                        if(element.id&&element.id.indexOf(parentId)> -1) {
                            return true;
                        }
                        element=element.parentNode;
                    }
                    return false;
                }
                        -->
            </script>

        </telerik:RadScriptBlock>
        <div class="exWrap">
            <div class="msgTop">
    <asp:CheckBox ID="UseDragColumnCheckBox" runat="server" OnCheckedChanged="UseDragColumnCheckBox_CheckedChanged"
    AutoPostBack="true" Text="Use GridDragDropColumn" />

            </div>
            <p class="howto">
                Select and drag orders from pending to shipped when dispatched<br />
                Reorder pending orders on priority by drag and drop<br />
                Drop a shipped order over the recycle bin to delete it</p>
            <div style="float: left; padding: 0 6px 0 10px">
                <h2 style="color: #9c3608">
                    Pending Orders</h2>
                <telerik:RadGrid runat="server" ID="grdPendingOrders" OnNeedDataSource="grdPendingOrders_NeedDataSource"
                    AllowPaging="True" Width="350px" OnRowDrop="grdPendingOrders_RowDrop" AllowMultiRowSelection="true"
                    PageSize="30" EnableHeaderContextMenu="true">
                    <MasterTableView DataKeyNames="OrderId" TableLayout="Fixed">
                        <Columns>
                            <telerik:GridDragDropColumn HeaderStyle-Width="18px" Visible="false" />
                        </Columns>
                    </MasterTableView>
                    <ClientSettings AllowRowsDragDrop="True" AllowColumnsReorder="true" ReorderColumnsOnClient="true">
                        <Resizing AllowColumnResize="true" />
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="false"/>
                        <ClientEvents OnRowDropping="onRowDropping" />
                        <Scrolling AllowScroll="true" UseStaticHeaders="true"/>
                    </ClientSettings>
                    <PagerStyle Mode="NumericPages" PageButtonCount="4" />
                </telerik:RadGrid>
            </div>
            <div style="float: right; padding: 0 10px 0 6px">
                <h2 style="color: #3c8b04">
                    Shipped Orders</h2>
                <telerik:RadGrid runat="server" AllowPaging="True" ID="grdShippedOrders" OnNeedDataSource="grdShippedOrders_NeedDataSource"
                    Width="350px" OnRowDrop="grdShippedOrders_RowDrop" AllowMultiRowSelection="true">
                    <MasterTableView DataKeyNames="OrderId" Width="100%">
                        <Columns>
                            <telerik:GridDragDropColumn HeaderStyle-Width="18px" Visible="false" />
                        </Columns>
                        <NoRecordsTemplate>
                            <div style="height: 30px; cursor: pointer;">
                                No items to view</div>
                        </NoRecordsTemplate>
                        <PagerStyle Mode="NumericPages" PageButtonCount="4" />
                    </MasterTableView>
                    <ClientSettings AllowRowsDragDrop="True">
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
                        <ClientEvents OnRowDropping="onRowDropping" />
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
            <div style="clear: both;">
                <!-- -->
            </div>
            <div class="exFooter">
                <a id="trashCan" href="#" onclick="return false;">Recycle Bin</a>
                <div class="exMessage" runat="server" id="msg" visible="false" enableviewstate="false">
                    Order(s) successfully deleted!
                </div>
            </div>
        </div>
        <!-- content end -->
        <telerik:Footer ID="Footer1" runat="server" AdditionalCodeViewerFiles="~/Grid/Examples/Programming/DragAndDrop/Common/example.css"></telerik:Footer>
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451