J
Jonathan Wood
I have a requirement to provide users with the ability to control the order
of items in a table, used by an ASP.NET application.
Requiring them to enter a number into a new column, which I would then sort
by, is not a valid option as it becomes too messy when they are adding,
deleting, or changing the order of items. Ideally, I would have an UP/DOWN
button for each item, and items would order as created but could then be
moved around using these buttons.
Does anyone have suggestions on an efficient way to implement this? I would
really like to minimize the number of database hits in implementing this.
For example, when writing a new item, I could do a query to return the
highest order value so far and store the new item with a value one higher.
And then when swapping the order of two items, I'd have to read both rows,
and then write both rows. I'd love to improve on the efficiency of this. I
don't suppose SQL has some sort of command to swap the column values of two
different rows.
Thanks!
of items in a table, used by an ASP.NET application.
Requiring them to enter a number into a new column, which I would then sort
by, is not a valid option as it becomes too messy when they are adding,
deleting, or changing the order of items. Ideally, I would have an UP/DOWN
button for each item, and items would order as created but could then be
moved around using these buttons.
Does anyone have suggestions on an efficient way to implement this? I would
really like to minimize the number of database hits in implementing this.
For example, when writing a new item, I could do a query to return the
highest order value so far and store the new item with a value one higher.
And then when swapping the order of two items, I'd have to read both rows,
and then write both rows. I'd love to improve on the efficiency of this. I
don't suppose SQL has some sort of command to swap the column values of two
different rows.
Thanks!