New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

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
10488FRANKFrankenversand4/24/1997
10489PICCOPiccolo und mehr4/25/1997
10490HILAAHILARION-Abastos4/28/1997
10491FURIBFuria Bacalhau e Frutos do Mar4/28/1997
10492BOTTMBottom-Dollar Markets4/29/1997
10493LAMAILa maison d'Asie4/30/1997
10494COMMIComércio Mineiro4/30/1997
10495LAUGBLaughing Bacchus Wine Cellars5/1/1997
10496TRADHTradição Hipermercados5/2/1997
10497LEHMSLehmanns Marktstand5/2/1997
10498HILAAHILARION-Abastos5/5/1997
10499LILASLILA-Supermercado5/6/1997
10500LAMAILa maison d'Asie5/7/1997
10501BLAUSBlauer See Delikatessen5/7/1997
10502PERICPericles Comidas clásicas5/8/1997
10503HUNGOHungry Owl All-Night Grocers5/9/1997
10504WHITCWhite Clover Markets5/9/1997
10505MEREPMère Paillarde5/12/1997
10506KOENEKöniglich Essen5/13/1997
10507ANTONAntonio Moreno Taquería5/13/1997
10508OTTIKOttilies Käseladen5/14/1997
10509BLAUSBlauer See Delikatessen5/15/1997
10510SAVEASave-a-lot Markets5/16/1997
10511BONAPBon app'5/16/1997
10512FAMIAFamilia Arquibaldo5/19/1997
10513WANDKDie Wandernde Kuh6/3/1997
10514ERNSHErnst Handel5/20/1997
10515QUICKQUICK-Stop5/7/1997
10516HUNGOHungry Owl All-Night Grocers5/22/1997
10517NORTSNorth/South5/22/1997
 Page 9 of 28, items 241 to 270 of 830.

Shipped Orders

Order IDCustomer IDCompanyDate
No items to view
Recycle Bin

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.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
  • scripts.js
<%@ Page Language="c#" AutoEventWireup="false" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.GridExamplesCSharp.ColumnsAndRows.Rows.DragAndDrop.DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link href="Common/example.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <script type="text/javascript" src="scripts.js"></script>
    <telerik:RadFormDecorator RenderMode="Lightweight" ID="RadFormDecorator1" DecorationZoneID="msgTop" DecoratedControls="CheckBoxes, Label" runat="server"
        Skin="Silk" EnableRoundedCorners="false"></telerik:RadFormDecorator>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxManager runat="server" ID="radAjax" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="grdPendingOrders">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="grdPendingOrders"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="grdShippedOrders"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="msg"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="grdShippedOrders">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="grdShippedOrders"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="msg"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="UseDragColumnCheckBox">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="grdPendingOrders"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="grdShippedOrders"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div class="demo-container" style="width: 750px;">
        <div class="exWrap">
            <div class="msgTop" id="msgTop">
                <asp:CheckBox ID="UseDragColumnCheckBox" runat="server" OnCheckedChanged="UseDragColumnCheckBox_CheckedChanged"
                    AutoPostBack="true" Text="Use DragDropColumn"></asp:CheckBox>
            </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 RenderMode="Lightweight" runat="server" ID="grdPendingOrders" Skin="Silk" OnNeedDataSource="grdPendingOrders_NeedDataSource"
                    AllowPaging="True" Width="350px" OnRowDrop="grdPendingOrders_RowDrop" AllowMultiRowSelection="true"
                    PageSize="30">
                    <MasterTableView DataKeyNames="OrderId" Width="100%" TableLayout="Fixed">
                        <Columns>
                            <telerik:GridDragDropColumn HeaderStyle-Width="18px" Visible="false">
                            </telerik:GridDragDropColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings AllowRowsDragDrop="True" AllowColumnsReorder="true" ReorderColumnsOnClient="true">
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="false"></Selecting>
                        <ClientEvents OnRowDropping="demo.onRowDropping"></ClientEvents>
                        <Scrolling AllowScroll="true" UseStaticHeaders="true"></Scrolling>
                    </ClientSettings>
                    <PagerStyle Mode="NumericPages" PageButtonCount="4"></PagerStyle>
                </telerik:RadGrid>
            </div>
            <div style="float: right; padding: 0 10px 0 6px">
                <h2 style="color: #3c8b04">Shipped Orders</h2>
                <telerik:RadGrid RenderMode="Lightweight" runat="server" AllowPaging="True" Skin="Silk" 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">
                            </telerik:GridDragDropColumn>
                        </Columns>
                        <NoRecordsTemplate>
                            <div style="height: 30px; cursor: pointer;">
                                No items to view
                            </div>
                        </NoRecordsTemplate>
                        <PagerStyle Mode="NumericPages" PageButtonCount="4"></PagerStyle>
                    </MasterTableView>
                    <ClientSettings AllowRowsDragDrop="True">
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="false"></Selecting>
                        <ClientEvents OnRowDropping="demo.onRowDropping" OnGridCreated="demo.onGridCreated"></ClientEvents>
                    </ClientSettings>
                </telerik:RadGrid>
            </div>
            <div style="clear: both;">
            </div>
            <div class="exFooter">
                <div id="trashCan" style="width: 75px">
                    Recycle Bin
                </div>
                <div class="exMessage" runat="server" id="msg" visible="false" enableviewstate="false">
                    Order(s) successfully deleted!
                </div>
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance