reorderlist doesnt save new order

Last post 10-06-2008 3:23 PM by robg_advernets. 10 replies.

Sort Posts:

  • reorderlist doesnt save new order

    12-31-2007, 3:16 PM
    • Member
      23 point Member
    • c2w-asif
    • Member since 10-17-2006, 3:36 AM
    • Posts 42

    Hi I am trying to use the reorderlist in association with code behind. My data is coming from an MSSQL database via a DAL and BLL. When i run the code the list appears fine and i can reorder elements howvever the new order is not being saved to the database. I cant figure out how to go about dynamically assigning the update command, please help.

     

    Page Code

     

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="OrderBy.ascx.vb" Inherits="usercontrols_OrderBy" %>
    <asp:ScriptManager ID="ScriptManager" runat="server" />
    <ajaxToolkit:ReorderList ID="rlPageContents" runat="server">
        <ItemTemplate>
           <asp:Panel ID="itemArea" runat="server">
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("Info1") %>' />
            </asp:Panel>
        </ItemTemplate>
        <ReorderTemplate>
            <asp:Panel ID="Panel2" runat="server" CssClass="reorderCue" />
        </ReorderTemplate>
        <DragHandleTemplate>
            <div class="dragHandle"></div>
        </DragHandleTemplate>
    </ajaxToolkit:ReorderList>

     Code Behind

    Partial Class usercontrols_OrderBy
        Inherits System.Web.UI.UserControl
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not Page.IsPostBack Then
                Dim pageContentLogic As New PageContentsBLL
                rlPageContents.DataSource = pageContentLogic.GetPageContentsByPageID(21)
                rlPageContents.DataKeyField = "ID"
                rlPageContents.SortOrderField = "OrderBy"
                rlPageContents.AllowReorder = True
                rlPageContents.PostBackOnReorder = False
                rlPageContents.DataBind()
    
            End If
        End Sub
    End Class
     
  • Re: reorderlist doesnt save new order

    01-01-2008, 8:43 AM
    Answer
    • Contributor
      4,243 point Contributor
    • impathan
    • Member since 07-12-2007, 10:12 AM
    • Ahmedabad
    • Posts 787

    c2w-asif:
    Hi I am trying to use the reorderlist in association with code behind. My data is coming from an MSSQL database via a DAL and BLL. When i run the code the list appears fine and i can reorder elements howvever the new order is not being saved to the database. I cant figure out how to go about dynamically assigning the update command, please help.
     

    You have to call ItemReorder event of reorder control to reorder index of rows.
    take one field as int and bind data in ascending order on page load event.
    whenever you change order of row you need to update that new order index in the database and rebind reorder list
    On ItemReorder event,you can get new order index and old order index as following way
     protected void ReorderList1_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)
        {
            int newIndex= e.NewIndex;
            int oldIndex= e.OldIndex;
            int newIndexPKEY= Convert.ToInt32(((Label)e.Item.FindControl("lblKey")).Text);
            int oldIndexPKEY=Convert.ToInt32(((Label)ReorderList1.Item[e.NewIndex].FindControl("lblKey")).Text);
            //Now you have two pkey for newIndex and old index,
            //You have two query to update record.first you can change newintemindex using newIndexPKEY,second by using oldindexPKEY
        }

    Click on 'Mark as Answer' if this post is helpful.

    ImranKhan pathan
  • Re: reorderlist doesnt save new order

    01-01-2008, 1:12 PM
    • Member
      23 point Member
    • c2w-asif
    • Member since 10-17-2006, 3:36 AM
    • Posts 42

    Hi Imran, thanks for your help, i am trying this now, quick question though, I assume i will have to change the postback settings to true so that it posts on reorder. If so how would i go about changing it so that i can just keep it as a client side script

  • Re: reorderlist doesnt save new order

    01-01-2008, 11:31 PM
    • Contributor
      4,243 point Contributor
    • impathan
    • Member since 07-12-2007, 10:12 AM
    • Ahmedabad
    • Posts 787

    c2w-asif:
    If so how would i go about changing it so that i can just keep it as a client side script
     

    You need to perform update operation so I think it will be better if you use codebehind code.Take reorderlist in update panel. 

    Click on 'Mark as Answer' if this post is helpful.

    ImranKhan pathan
  • Re: reorderlist doesnt save new order

    01-08-2008, 5:26 PM
    • Member
      8 point Member
    • burty
    • Member since 01-08-2008, 10:21 PM
    • Posts 4

    Hi,

    In the original code I do not see any labels, or references to 'lblKey'? Therefore these lines are confusing me:

    int newIndexPKEY= Convert.ToInt32(((Label)e.Item.FindControl("lblKey")).Text);
    int oldIndexPKEY=Convert.ToInt32(((Label)ReorderList1.Item[e.NewIndex].FindControl("lblKey")).Text);

    What am I searching for using the label 'lblKey'?

    many thanks

    Burty.

     

  • Re: reorderlist doesnt save new order

    01-08-2008, 5:48 PM
    Answer
    • Member
      23 point Member
    • c2w-asif
    • Member since 10-17-2006, 3:36 AM
    • Posts 42

    Hi Burty, my solution ended up being a little different to what is above. the code is as follows. the LoadReorderList is just a subroutine that populates the reorderlist and should also be in your page load.

     

       Protected Sub rlPageContents_ItemReorder(ByVal sender As Object, ByVal e As AjaxControlToolkit.ReorderListItemReorderEventArgs) Handles rlPageContents.ItemReorder
            Dim sbMessage As New System.Text.StringBuilder()
            Dim lowerBound As Integer = (IIf(e.OldIndex > e.NewIndex, e.NewIndex, e.OldIndex))
            Dim upperBound As Integer = (IIf(e.OldIndex > e.NewIndex, e.OldIndex, e.NewIndex))
            Dim incrementer As Integer = (IIf(e.OldIndex > e.NewIndex, 0, 1))
    
            sbMessage.Append("LowerBound : " & lowerBound)
            sbMessage.Append("<br>upperbound : " & upperBound)
            sbMessage.Append("<br>Incrementer : " & incrementer)
            Dim pageContentLogic As New PageContentsBLL()
    
            Dim ID As Integer = Convert.ToInt32(rlPageContents.DataKeys(e.OldIndex))
            Dim OrderBy As Integer = Convert.ToInt32(e.NewIndex)
            Dim updated As Boolean = pageContentLogic.UpdatePageContentOrderByID(ID, OrderBy)
            sbMessage.Append("<br>Iteration : 0<br>")
            sbMessage.Append("ID : " & ID & " ---- OrderBy : " & OrderBy)
            For i As Integer = lowerBound + incrementer To upperBound + (incrementer - 1)
    
                ID = Convert.ToInt32(rlPageContents.DataKeys(i))
                OrderBy = i + (IIf(incrementer = 0, 1, -1))
                updated = pageContentLogic.UpdatePageContentOrderByID(ID, OrderBy)
                sbMessage.Append("<br>Iteration : " & i & "<br>")
                sbMessage.Append("ID : " & ID & " ---- OrderBy : " & OrderBy)
            Next
            LoadReorderList()
            'lblMessage.Text = sbMessage.ToString()
        End Sub
     hope this helps let me know if there is anything else
  • Re: reorderlist doesnt save new order

    01-08-2008, 5:55 PM
    • Member
      8 point Member
    • burty
    • Member since 01-08-2008, 10:21 PM
    • Posts 4

    Aha, thanks. I'll give that a go.

    Burty.

  • Re: reorderlist doesnt save new order

    01-09-2008, 4:30 PM
    • Member
      8 point Member
    • burty
    • Member since 01-08-2008, 10:21 PM
    • Posts 4

    Actually, wonder if you could post the pageContentLogic.UpdatePageContentOrderByID(ID, OrderBy) method?

    thanks for the help!

    Burty.

     

     

  • Re: reorderlist doesnt save new order

    01-10-2008, 5:27 AM
    • Member
      23 point Member
    • c2w-asif
    • Member since 10-17-2006, 3:36 AM
    • Posts 42

    Sure here it is, this then connect to a dataset which has the actual update SQL. All that this is updating is the OrderBy field in my database table. The ID field is just the primary key for that table to ensure the correct row is updated.

     

        <System.ComponentModel.DataObjectMethodAttribute _
        (System.ComponentModel.DataObjectMethodType.Update, True)> _
        Public Function UpdatePageContentOrderByID( _
        ByVal id As Integer, _
        ByVal orderbyid As Integer) _
        As Boolean
    
            Dim pageContents As Place2Be.PageContentsDataTable = Adapter.GetPageContentByID(id)
            'Adapter.GetProductByProductID(productID)
    
            If pageContents.Count = 0 Then
                Return False
            End If
            'Dim pageContents As New Place2Be.PageContentsDataTable
            Dim pageContent As Place2Be.PageContentsRow = pageContents(0)
    
            pageContent.OrderBy = orderbyid
    
            Dim rowUpdated As Integer = Adapter.Update(pageContent)
    
            Return rowUpdated
        End Function
     
  • Re: reorderlist doesnt save new order

    04-10-2008, 2:43 PM
    • Member
      11 point Member
    • rh1200
    • Member since 09-09-2007, 6:58 AM
    • Posts 40

    Hey...thanks for posting this reorderlist save code.  It was exactly what I was looking for.

     

     

  • Re: reorderlist doesnt save new order

    10-06-2008, 3:23 PM

    I found this example. Seems to be a great example.

    http://www.codeproject.com/KB/ajax/RealtimeReorderList.aspx?msg=2753593

     It's a great example. I'm still new to ASP.NET 3.0. Can someone explain to me how I would convert this from LINQ to SQL datatype. 

     
    1    var db = new RealTimeReorderListDataDataContext();
    2    
    3    int ListItemCount = 1;            
    4    
    5    var ListData = from ld
    6                     in db.ReorderListItems
    7                     orderby ld.ListOrder
    8                     select ld;            
    9    
    10   foreach (var ListDataItem in ListData)
    11   {
    12   
    13   }
    14   
    
     
     

     

    ----------------------------------------
    I'm a programmer because coding is FUN!
    "quoted by Rob Gerwing"
    ----------------------------------------
Page 1 of 1 (11 items)