gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:10:50 25 4
gpt4 key购买 nike

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

想法:当我拖动时,我假设我可以在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com