Drag and Drop Example

 

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="Default.aspx.vb" Inherits="TaskList._Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function CellValueChanged() {
            var grid1 = $find("<%=RadGrid1.ClientID%>");
            grid1.get_batchEditingManager().saveAllChanges();
        }
 
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 
 
    <telerik:RadAjaxPanel runat="server"></telerik:RadAjaxPanel>
 
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" CssClass="grid" >
        <ClientSettings AllowRowsDragDrop="true" AllowKeyboardNavigation="true">
            <ClientEvents OnBatchEditCellValueChanged="CellValueChanged" />
           <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
            
        </ClientSettings>   
     
        <MasterTableView DataKeyNames="RowID, LineID" EditMode="Batch"   >
            <BatchEditingSettings SaveAllHierarchyLevels="true"  />
            <Columns>
                <telerik:GridBoundColumn DataField="TaskText" HeaderText="Text"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Completed" HeaderText="Comp Date " DataFormatString="{0:MM/dd/yyyy}"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Status" HeaderText="Status"></telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
 
 
</asp:Content>

 

Imports Telerik.Web.UI
 
Public Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    End Sub
 
    Private Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        Try
            Me.RadGrid1.DataSource = SPs.dd_TaskList_SEL().getTable
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, False)
        End Try
 
    End Sub
 
    Private Sub RadGrid1_RowDrop(sender As Object, e As GridDragDropEventArgs) Handles RadGrid1.RowDrop
        Try
            If String.IsNullOrEmpty(e.HtmlElement) Then
                'reorder items in pending grid
                Dim intDestinationLineID As Int32 = e.DestDataItem.GetDataKeyValue("LineID")
                Dim intDraggedLineID As Int32 = e.DraggedItems(0).GetDataKeyValue("LineID")
 
                If ((e.DropPosition = GridItemDropPosition.Above) AndAlso (e.DestDataItem.ItemIndex > e.DraggedItems(0).ItemIndex)) Then
                    intDestinationLineID = (intDestinationLineID - 1)
                End If
                If ((e.DropPosition = GridItemDropPosition.Below) AndAlso (e.DestDataItem.ItemIndex < e.DraggedItems(0).ItemIndex)) Then
                    intDestinationLineID = (intDestinationLineID + 1)
                End If
 
                SPs.dd_TaskList_SwapLineID(intDestinationLineID, intDraggedLineID).execute()
 
 
                RadGrid1.Rebind()
 
            End If
 
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, False)
        End Try
    End Sub
 
    Private Sub RadGrid1_BatchEditCommand(sender As Object, e As GridBatchEditingEventArgs) Handles RadGrid1.BatchEditCommand
        Try
            For Each command As GridBatchEditingCommand In e.Commands
                Dim strTaskText As String
                Dim newValues As Hashtable = command.NewValues
 
                '' Access the new values
                Dim RowID As Int32 = newValues("RowID")
                strTaskText = newValues("TaskText")
 
                '' Logic to Save the new values into the database
                Dim oTaskList As New DAL.TaskList(RowID)
                If Not oTaskList.ispopulated Then
                    Exit Sub
                End If
                oTaskList.TaskText = strTaskText
                oTaskList.Save()
 
 
            Next
        Catch ex As Exception
            ErrorHandler.globalErrorHandler(ex, False)
 
        End Try
    End Sub
End Class

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences