I am using asp.net (3.5). I have GridView and I need to use Drag&Drop for purpose to reorder items (table rows) and save new order to db.
I have found out that I can use jquery.tablednd plugin for this purpose.
DnD functionality really works for me, but I cannot reorder items and save in db, because ON DROP never works for me.
I have tried to copy different examples I found in web, but ondrop never works for me. I have created new file to do tests (my original page uses masterpage). I have included ajaxToolkit:ToolkitScriptManager , but I have also tried it with asp:ScriptManager. DropAndDrag is working, but ON DROP event is never called. OnDragStart event is called successfully. Please, have a look to my code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="News.aspx.cs" Inherits="Tutelaconnect.News" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
<script src="http://www.isocra.com/articles/jquery.tablednd.js" type="text/javascript">
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#<%= GridViewSample.ClientID %>").tableDnD({
onDrop: function (table, row) {
alert('1'); ///// THIS NEVER HAPPEN
},
onDragStart: function (table, row) {
// alert('2'); //// THIS HAPPENS
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<div id="debugArea">
</div>
<div class="tableDemo">
<asp:GridView ID="GridViewSample" runat="server" AutoGenerateSelectButton="false"
AutoGenerateColumns="false" Width="800px">
<Columns>
<asp:TemplateField HeaderText="C">
<ItemTemplate>
<asp:TextBox ID="TextBoxC" runat="server" Text='<%# Eval("C") %>' Width="50px" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" Width="10em" />
</asp:TemplateField>
<asp:TemplateField HeaderText="A">
<ItemTemplate>
<asp:Label ID="LabelA" runat="server" Text='<%# Eval("A") %>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Left" Width="30em" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
I am really stuck. Do not know how to continue.
I found the solution here: http://www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/comment-page-15/#comment-3460
Basically, each row in your table needs an Id, you can use code like this to give them one:
var i = 0;
$("#<%= GridViewSample.ClientID %>").find('tr').each(function() {
$(this).attr('id', i++);
});
I placed this code right before: $("#<%= GridViewSample.ClientID %>").tableDnD
and was able to get the alert(1);
box displaying each time I dropped a row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With