Blog

Getting the AJAX ReorderList to work

I've been working on a tool that allows a set of hierarchical items to be reordered in whatever level of the hierarchy they reside. Basically, I wanted to be able to navigate down the hierarchy and reorder within each level. This was kind of a task. The example that is provided shows very little about hooking up actual, dynamic data to the control, and nothing about actually UPDATING that data on the fly. For the updating piece, I found this extremely useful article. Unfortunately for me, I never use objectdatasource controls and am completely unfamiliar with navigating them. (I usually prefer to do all of my data connection in the code behind.) I struggled for a while trying to translate the advice in the article above with the way I prefer to do things, and ultimately failed. Instead, I used the advice exactly for my updates, and after a little trial and error, voila! My reorders updated as soon as you dragged and dropped. The trick he mentions is to make sure that ALL of the fields pulled in your select command (in the below procedure defined in the SelectMethod, basically whatever columns are in your SELECT statement) are also included in the update procedure, even if they aren't necessary for making the update. <cc1:ReorderList ID="ajaxReorder" runat="server" DataSourceID="ODS1" PostbackOnReorder="true"... ></cc1:ReorderList> <asp:ObjectDataSource id="ODS1" runat="server" SelectMethod="SelectReorderList" TypeName="NavigationExample" UpdateMethod="UpdateReorderList"> <UpdateParameters> <asp:Parameter Name="ItemID" Type="Object" /> <asp:Parameter Name="MenuOrder" Type="Int32" /> <asp:Parameter Name="ItemText" Type="String" /> </UpdateParameters> </asp:ObjectDataSource><asp:ObjectDataSource id="ODS1" runat="server" SelectMethod="SelectReorderList" TypeName="NavigationExample" UpdateMethod="UpdateReorderList"> <UpdateParameters> <asp:Parameter Name="ItemID" Type="Object" /> <asp:Parameter Name="MenuOrder" Type="Int32" /> <asp:Parameter Name="ItemText" Type="String" /> </UpdateParameters> </asp:ObjectDataSource> Code Behind public void UpdateReorderList(Guid ItemID, Int32 MenuOrder, string ItemText) { //Do stuff to update //ItemText isn't required to update the item order //but you must pass it in anyway because //it was called in the select statement } Another challenge came into play when trying to bind the list with parameters dynamically. I'm sure someone with more extensive ObjectDataSource experience would find my problem a piece of cake, but in the end I did the following when trying to bind (or rebind) the Reorder list with dynamic values: (The below was inserted right after the UpdateParameters.) <SelectParameters> <asp:Parameter Name="ParentID" Type="Int32" /> </SelectParameters> Code Behind ODS1.SelectParameters["ParentID"].DefaultValue = navitem.ParentID.ToString(); ODS1.Select(); Finally, everything works! Well, almost everything. I've found that the dragging works when I drag up, or in between items, but not when I drag an item to the bottom of the list. In fact, it doesn't even fire the Update procedure! I'm still looking for an answer to that problem. If/when I find it, I will update it here. In the meantime, if anyone stumbles across this post and knows the answer, leave me a comment!

Posted by on Mon, 24 Aug 2009
tags:


Comments

2 comments

  1. Hrydac Fri, 20 Aug 2021

  2. Lligvo Tue, 4 May 2021


Submit a Comment

Please insert the result of the arithmetical operation from the following image:

Please insert the result of the arithmetical operation from this image. =