rad grid, drag and drop
2013-06-06 21:51
429 查看
<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/admin.master" AutoEventWireup="true" CodeFile="testDragDrop.aspx.cs" Inherits="Admin_policy_testDragDrop" %> <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <%--<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />--%> <telerik:RadFormDecorator ID="RadFormDecorator1" DecoratedControls="All" runat="server" Skin="Metro" EnableRoundedCorners="false"></telerik:RadFormDecorator> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Width="256px" Height="64px" MinDisplayTime="5000"> <asp:Label ID="Label2" runat="server" ForeColor="Red">Loading... </asp:Label> </telerik:RadAjaxLoadingPanel> <%-- <asp:Image ID="Image1" runat="server" Width="224px" Height="48px" ImageUrl="~/Loading.gif"></asp:Image>--%> <telerik:RadAjaxManager runat="server" ID="radAjax" DefaultLoadingPanelID="RadAjaxLoadingPanel1"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="grdPolicy"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="grdPolicy" ></telerik:AjaxUpdatedControl> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadScriptBlock runat="server" ID="scriptBlock"> <script type="text/javascript"> //<![CDATA[ function onRowDropping(sender, args) { if (sender.get_id() == "<%=grdPolicy.ClientID %>") { var node = args.get_destinationHtmlElement(); if (!isChildOf('<%=grdPolicy.ClientID %>', node)) { 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"> <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="grdPolicy" AutoGenerateColumns="false" AllowPaging="True" Width="350px" AllowMultiRowSelection="true" PageSize="30" onneeddatasource="grdPolicy_NeedDataSource" onrowdrop="grdPolicy_RowDrop" ondeletecommand="grdPolicy_DeleteCommand" onitemcommand="grdPolicy_ItemCommand" > <MasterTableView DataKeyNames="PolicyId" Width="100%" TableLayout="Fixed" CssClass="table table-bordered table-primary" > <Columns> <telerik:GridDragDropColumn HeaderStyle-Width="18px" Visible="false"> </telerik:GridDragDropColumn> <telerik:GridBoundColumn HeaderText="Policy Name" DataField="Name"></telerik:GridBoundColumn> <telerik:GridTemplateColumn> <ItemTemplate> <asp:HyperLink runat="server" NavigateUrl='<%# Eval("PolicyId","edit.aspx?PolicyId={0}") %>' CssClass="btn-action no-border glyphicons edit btn-table"><i></i></asp:HyperLink> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn> <ItemTemplate> <asp:LinkButton ID="BtnDelete" runat="server" CssClass="btn-action no-border glyphicons remove_2 btn-table" CommandArgument='<%# Eval("PolicyId") %>' CommandName="Delete" OnClientClick="javascript: return confirm('Are you sure?');"><i></i></asp:LinkButton> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> <ClientSettings AllowRowsDragDrop="True" AllowColumnsReorder="true" ReorderColumnsOnClient="true"> <Selecting AllowRowSelect="True" EnableDragToSelectRows="false"></Selecting> <ClientEvents OnRowDropping="onRowDropping"></ClientEvents> <Scrolling AllowScroll="true" UseStaticHeaders="true"></Scrolling> </ClientSettings> <%--<PagerStyle Mode="NumericPages" PageButtonCount="4"></PagerStyle>--%> </telerik:RadGrid> </div> <div style="clear: both;"> </div> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Web.UI; using Telerik.Web.UI; using HRASP.Entities; using HR.Managers.Library.Managers; public partial class Admin_policy_testDragDrop : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { grdPolicy.MasterTableView.GetColumn("DragDropColumn").Visible = true; } protected TList<Policy> Policies { get { try { object obj = Session["Policies"]; if (obj == null) { obj = PolicyManager.GetAllPolicies(); if (obj != null) { Session["Policies"] = obj; } else { obj = new TList<Policy>(); } } return (TList<Policy>)obj; } catch (Exception ex) { Session["PendingPolicys"] = null; } return new TList<Policy>(); } set { Session["Policies"] = value; } } protected void grdPolicy_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { grdPolicy.DataSource = Policies; } private void UpdateSortOrder() { TList<Policy> list = (TList<Policy>)Policies; PolicyManager.UpdatePoliciesSortOrder(list); } protected void grdPolicy_RowDrop(object sender, GridDragDropEventArgs e) { if (string.IsNullOrEmpty(e.HtmlElement)) { // check drag from which grid if (e.DraggedItems[0].OwnerGridID == grdPolicy.ClientID) { // check drop to whcih grid if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdPolicy.ClientID) { //rePolicy items in pending grid TList<Policy> list = Policies; var obj1 = e.DestDataItem.GetDataKeyValue("PolicyId"); Policy p = GetPolicy(list, (Guid)e.DestDataItem.GetDataKeyValue("PolicyId")); int destinationIndex = list.IndexOf(p); 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; } TList<Policy> PolicysToMove = new TList<Policy>(); foreach (GridDataItem draggedItem in e.DraggedItems) { Policy tmpPolicy = GetPolicy(list, (Guid)draggedItem.GetDataKeyValue("PolicyId")); if (tmpPolicy != null) PolicysToMove.Add(tmpPolicy); } foreach (Policy PolicyToMove in PolicysToMove) { list.Remove(PolicyToMove); list.Insert(destinationIndex, PolicyToMove); } Policies = list; grdPolicy.Rebind(); //int destinationItemIndex = destinationIndex - (grdPendingPolicys.PageSize * grdPendingPolicys.CurrentPageIndex); //e.DestinationTableView.Items[destinationItemIndex].Selected = true; } } } } private static Policy GetPolicy(IEnumerable<Policy> PolicysToSearchIn, Guid policyId) { foreach (Policy Policy in PolicysToSearchIn) { if (Policy.PolicyId == policyId) { return Policy; } } return null; } protected void Button1_Click(object sender, EventArgs e) { UpdateSortOrder(); } protected void grdPolicy_DeleteCommand(object sender, GridCommandEventArgs e) { } protected void grdPolicy_ItemCommand(object sender, GridCommandEventArgs e) { //if (e.CommandName == "Delete") //{ // string s = e.CommandArgument.ToString(); //} try { Guid uid = new Guid(); if (Guid.TryParse(e.CommandArgument.ToString(), out uid)) { if (uid != Guid.Empty) { if (e.CommandName == "Delete") { PolicyManager.DeletePolicy(uid); Policies = null; // get latest data from db } } } } catch (Exception ex) { } } }
相关文章推荐
- Drag and Drop from Grid to Grid Example,增加上下、左右移动的功能。
- Grid Drag and Drop reorder rows
- Drag and Drop from Grid to Grid Example,增加上下、左右移动的功能。
- Drag and Drop Grid (ExtJS - 2)
- 虚幻引擎UE4背包系统(如何制作可拖动(Drag and Drop)的背包(Scrollbox))
- Drag-and-Drop(Chapter 23 of Cocoa Programming for Mac OS X)
- SWT 应用程序 实现的Drag and Drop(DND) 和 GEF 树上元素的拖拽
- EasyUI-treegrid-拖拽的实现(drag and drop)
- [jQuery]Drag And Drop Everything With 30 Handy jQuery Plugins
- 流水账 5.4 WPF中的拖拽 Drag-and-Drop
- Qt Drag and Drop Puzzle Example 看看看~
- silverlight - DragAndDropSample 示例
- QTP之drag and drop
- Android 用户界面---拖放(Drag and Drop)(二)
- JAVA.SWT/JFace: SWT Drag and Drop
- 用DHTML实现drag and drop的效果
- 分享一个HTML5的drag and drop API实现的图片拖拽分组效果
- 基于HTML5的Drag and Drop生成图片Base64信息
- 组件的拖拽功能(Drag and Drop)
- 封装一个Drop and Drag面板控件,供大家分享