asp.net drag and drop gridview

Hi,

I found an example of a gridview that I can reorder via drag and drop. The user drags the row to a second gridview and it keeps the new order.

 <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js" type="text/javascript"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
<script type="text/javascript">
    $(function () {
        $(".drag_drop_grid").sortable({
            items: 'tr:not(tr:first-child)',
            cursor: 'crosshair',
            connectWith: '.drag_drop_grid',
            axis: 'y',
            dropOnEmpty: true,
            receive: function (e, ui) {
                $(this).find("tbody").append(ui.item);
            }
        });
        $("[id*=gvDest] tr:not(tr:first-child)").remove();
    });
</script>

 <asp:GridView ID="gvSource" runat="server" CssClass="drag_drop_grid GridSrc" AutoGenerateColumns="false">
    <Columns>
     <asp:BoundField DataField="PID" HeaderText="VoteID"/>
     <asp:BoundField DataField="CustID" HeaderText="CustID"/>
     <asp:BoundField DataField="FeatureID" HeaderText="FeatureID"/>
     <asp:BoundField DataField="DESC" HeaderText="ShortDESC"/>
    </Columns>
</asp:GridView>

 <asp:GridView ID="gvDest" runat="server" CssClass="drag_drop_grid GridSrc" AutoGenerateColumns="false">
    <Columns>
     <asp:BoundField DataField="PID" HeaderText="VoteID"/>
     <asp:BoundField DataField="CustID" HeaderText="CustID"/>
     <asp:BoundField DataField="FeatureID" HeaderText="FeatureID"/>
     <asp:BoundField DataField="DESC" HeaderText="ShortDESC"/>

    </Columns>
</asp:GridView>


        For Each row As GridViewRow In gvDest.Rows

    
            Dim PID As String = row.Cells(0).Text
            Dim custID As String = row.Cells(1).Text
            Dim featureID As String = row.Cells(2).Text
            Dim DESC As String = row.Cells(3).Text
            Dim position As String = row.Cells(4).Text

        Next

Open in new window


The problem is, my code doesn't see the new order. Just the original order even though it's changed on the screen.

I need to be pointed in the right direction.


Thanks for any help.
someonenamedbrendanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
        $(function () {
            $(".drag_drop_grid").sortable({
                items: 'tr:not(tr:first-child)',
                cursor: 'crosshair',
                connectWith: '.drag_drop_grid',
                axis: 'y',
                dropOnEmpty: true,
                receive: function (e, ui) {
                    $(this).find("tbody").append(ui.item);
                },
                stop: function (e, ui) {
                    var gridview = ui.item.closest(".drag_drop_grid");
                    var pids = [];
                    $("tr:gt(0)", gridview).each(function () {
                        var pid = $("td:first", this).text();
                        pids.push(pid);
                    });
                    PageMethods.SaveOrder(pids, function (d) {
                        alert("order saved!");
                    }, function () { alert("error!"); });
                }
            });
            $("[id*=gvDest] tr:not(tr:first-child)").remove();
        });

Open in new window


    <System.Web.Services.WebMethod()> _
    <System.Web.Script.Services.ScriptMethod()> _
    Public Shared Function SaveOrder(pids As String()) As String
        // save to database
        Return "ok"
    End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
someonenamedbrendanAuthor Commented:
I've requested that this question be deleted for the following reason:

did it completely another way.
0
leakim971PluritechnicianCommented:
which way? does that mean my solution is not right?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.