Link to home
Start Free TrialLog in
Avatar of ratkinso666
ratkinso666

asked on

Reorder Items in sql database

Hi all, looking for some help on re-ordering.  I have a parent with several siblings, the siblings are ordered by a display_order field.  I need to be able to drop a NEW sibling in the middle and re-order the siblings accordingly...  I am thinking about making the display_order field go by 10's or 100's, and drop a new one in the middle, but I really don't like this solution and it would eventually fill up anyway.  I'm sure there is some GREAT code out there to help out with this, or at least some ideas on how to go about it.  I am doing this in Visual Studio 2005 VB.net.  They are adding the siblings in via a detailsview grid.

Thanks,
Randy
ASKER CERTIFIED SOLUTION
Avatar of chrios
chrios
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GO-87
GO-87

Instead of trying to manually insert numbers between existing numbers, which will eventually require renumbering (even if you were to use decimals, you'd eventually run out of numbers), why not implement the list in a simple Collection?
This would still require that you are able to identify the next (or previous) sibling when you're about to insert the new sibling
For example:
Private colSiblings As New Collection
Then you can insert a new sibling relative to its adjacent sibling, for example:
colSiblings.Add(argNewSibling,  , argBeforeSibling, )
or
colSiblings.Add(argNewSibling,  ,  , argAfterSibling)
Avatar of ratkinso666

ASKER

Sounds like a great idea, I like it.  Would I somehow do that in the ItemInserting section??  
Yes,
argNewSibling would be an object (or a number, or a string, ...) representing the new sibling; and argBeforeSibling (or argAfterSibling) would be the desired neighbour for the new sibling. Remember, if you've inserted the items as numbers, then you need to refer to numbers when you compare (and likewise, if you inserted strings, you need to compare against strings).
I hope that makes sense.
coming along nicely, but what is the syntax to pass more than one value from the gridview to the detailsview??  I have two parameters (in the datakey names) in the gridview BA_ID, BA_DispOrder.  I need the BA_ID to pass to my next gridview and since it is my primary I have no problem using it, but I need the BA_DispOrder to know my selection from the gridview, after I get this last part I will be finished with this.  This is what I am trying to use in my Insert Parameters section:
<asp:ControlParameter ControlID="GridView2" Name="BA_DispOrder" PropertyName="SelectedValue"
                                                Type="Int32" />
I need it as my value, this works for the first parameter in a list, but I guess not for the secondary one??
Thanks,
Randy
I know in the code behind I would get it like this:

        Dim NewOrder As String = (GridView2.SelectedDataKey.Values("BA_DispOrder").ToString())

so, I could run an update on this in the code behind, after I do my insert, but I would rather do it on the insert from the detailsview...
Thank you for the excellent help!!!