javascript - 拖放更改后将更改保存到数据网格

标签 javascript jquery asp.net vb.net

问题:网格现在可以向上或向下拖动行。我想保存订单更改,我已经搜索过但找不到方法

想法:当我拖动时,我假设我可以在 JavaScript/jQuery 中获取 ID 并以这种方式保存更改?

代码:

(.aspx)

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Grid.aspx.vb" Inherits="Grid" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<!-- Drag and drop feature --> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="jquery.tablednd.js"></script>
<script type="text/javascript">
    $(function () {
        $("#gvDetails").tableDnD();
    })
</script>

<!-- /// Drag and drop feature --> 
</head>
<body>
    <form id="form1" runat="server">
    <div>     
<hr />
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="true" EmptyDataText = "No files uploaded">
    <Columns>
   <asp:BoundField DataField="Text" HeaderText="File Name" />
    </Columns>
</asp:GridView>

    </div>
    </form> 
</body>
</html>

(.aspx.vb)

Imports System.IO
Imports System.Data
Imports System.Collections.Generic

Partial Class Grid
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If Not IsPostBack Then
            BindGridviewData()
        End If
    End Sub

    Protected Sub BindGridviewData()


        Dim filePaths() As String = Directory.GetFiles(Server.MapPath("~/Uploads/"))
        Dim files As List(Of ListItem) = New List(Of ListItem)
        For Each filePath As String In filePaths
            files.Add(New ListItem(Path.GetFileName(filePath), filePath))
        Next

        gvDetails.DataSource = files
        gvDetails.DataBind()

    End Sub

End Class

引用文献:

代码基于:http://www.aspdotnet-suresh.com/2015/03/aspnet-gridview-reorder-rows-with-drag-drop-options-using-jquery-tablednd-plugin.html

搜索(示例):http://forums.asp.net/t/2042661.aspx?Drag+and+drop+and+save+automatically+with+Datagrids

最佳答案

您可以在调用方法 tableDnD 时捕获事件 onDrop 并保存更改:

$("#gvDetails").tableDnD(
    onDrop: function(table, row) {
        console.log("Save changes");
    }
);

您可以查看此文档:

https://github.com/isocra/TableDnD/blob/master/js/jquery.tablednd.js

或者,如果您已经弄清楚了这一点,也许其他答案可以帮助您:

TableDnD onDrop event not firing

关于javascript - 拖放更改后将更改保存到数据网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074638/

相关文章:

javascript - 如何在 URL 中包含特定主题标签时显示文本?

javascript - Quickblox 使用 Javascript SDK 进行群组视频通话

javascript - 如何将 JS 日期对象传递给云函数以将其存储在 Firestore 上

当元素进入视口(viewport)时,JavaScript/jQuery 添加类?

javascript - 最接近的 jquery 函数能否在其他标签中找到子标签

c# - C# 中的类和方法,这是一个好方法吗?

javascript - 为什么当用户关闭 chrome 中的选项卡时弹出?

javascript - 有没有办法在运行时使用 jquery 克隆硬编码元素或元素集?

c# - ASP.NET 站点重定向帮助

asp.net - 在 ASP.NET 中实现 "Remember me"功能