Click here to Skip to main content
15,885,920 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,
i need not to remove the dragged item from the list
any help please?

C#
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js" type="text/javascript"></script>
    <link href="http://code.jquery.com/ui/1.8.24/themes/blitzer/jquery-ui.css" rel="stylesheet"
        type="text/css" />
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
        .draggable
        {
            filter: alpha(opacity=60);
            opacity: 0.6;
        }
        .dropped
        {
            position: static !important;
        }
        #dvSource, #dvDest
        {
            border: 5px solid #ccc;
            padding: 5px;
            min-height: 100px;
            width: 430px;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $("#DataList1 Table").draggable({
                revert: "invalid",
                refreshPositions: true,
                drag: function (event, ui) {
                    ui.helper.addClass("draggable");
                }
            });
            $("#dvDest").droppable({
                drop: function (event, ui) {
                    if ($("#dvDest table").length == 0) {
                        $("#dvDest").html("");
                    }
                    ui.draggable.addClass("dropped");
                    $("#dvDest").append(ui.draggable);
                    $("#dvDest").append("<hr />");
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div id="dvSource">
        <asp:DataList ID="DataList1" runat="server">
            <itemtemplate>
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            Id
                        </td>
                        <td>
                            <asp:Label Text='<%# Eval("Id") %>' runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Name
                        </td>
                        <td>
                            <asp:Label Text='<%# Eval("Name") %>' runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Country
                        </td>
                        <td>
                            <asp:Label Text='<%# Eval("Country") %>' runat="server" />
                        </td>
                    </tr>
                </table>
            </itemtemplate>
        
    </div>
    <hr />
    <div id="dvDest">
        Drop here
    </div>
    </form>
</body>
</html>


C++
using System.Data;
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
                        new DataColumn("Name", typeof(string)),
                        new DataColumn("Country",typeof(string)) });
        dt.Rows.Add(1, "John Hammond", "United States");
        dt.Rows.Add(2, "Mudassar Khan", "India");
        dt.Rows.Add(3, "Suzanne Mathews", "France");
        dt.Rows.Add(4, "Robert Schidner", "Russia");
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }
}
Posted
Updated 13-Aug-14 3:33am
v3

1 solution

Use this code.

Just replace your code inside tag.
<pre lang="xml">&lt;script type=&quot;text/javascript&quot;&gt;
$(function () {
$(&quot;#DataList1 Table&quot;).draggable({
revert: &quot;invalid&quot;,
refreshPositions: true,
helper: 'clone',
cursor: 'hand',
drag: function (event, ui) {
ui.helper.addClass(&quot;draggable&quot;);
}
});

$(&quot;#dvDest&quot;).droppable({
accept: &quot;#DataList1 Table&quot;,
hoverClass: 'dropareahover',
tolerance: 'pointer',
drop: function (event, ui) {
var dropElemId = ui.draggable.attr(&quot;id&quot;);

var dropElem = ui.draggable.html();

clone = $(dropElem).clone(); // clone it and hold onto the jquery object
clone.id = &quot;newId&quot;;
clone.css(&quot;position&quot;, &quot;absolute&quot;);
clone.draggable({ containment: 'parent', cursor: 'crosshair' });

$(this).append(clone);
$('#newId').css(&quot;visibility&quot;, &quot;hidden&quot;);

$(&quot;#dvDest&quot;).append(&quot;&lt;hr /&gt;&quot;);

}
});
});
&lt;/script&gt;</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900