I need help.
I'm stuck on this ASP.Net application. I have a few controls on the page that all link up to 2 tables. The one I am stuck on is the Ajax Reorderlist. The Reorderlist is a list that has drag-and-drop capability. You can drag each item in the list and reorder it. For a demo of the Reorderlist, see this link: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ReorderList/ReorderList.aspx
My reorderlist is hooked up to a SQL datasource and it displays a list of items. The client wants to be able to change the order of the items so that the items appear on the main page of the website in a particular order. At first glance, the Reorderlist seems to be just the answer.
This is my problem: how do I add new records and still be able to reorder them? I have the datasource connected to the Reorderlist and it all works great, as long as I don't add new records to the database. Here's the thing: when you set up the table that holds the items you are going to reorder, you have to add a column to the table with a datatype of INT and this column will hold the Sort Order. This column cannot contain Null values. When you drag and drop the list items on the page, the Sort Order is posted back to the server and the values in the Sort Order column of the table are updated.
So, for instance, if I have 3 items in my table and they start out like this:
And if I drag and drop them, then check the table after the post-backs occur, I will see something like this:
Now, if I add a new record, what the heck do I put in the SortOrderID field for a value? I can't auto-increment that column for 2 reasons: #1, ItemID is already an Identity column and I can't have 2 Identity columns; and #2, the values in an identity column keep their value even if you try to reorder them - they don't update.
I could query for the largest SortOrderID value just before I insert a new record and then add "1" to it, which will give me the next available value, then insert that number into the table. But that is my last choice. It's too risky to do that -- what happens when 2 people are adding new records at the exact same time and they pull that value at exactly the same time? It'll screw up the Reorderlist and I'll get a call telling me that it's not working. And then I'll be right back where I am now.
I tried to make the default value zero (0) on inserting, which does technically work but it is extremely sloppy. When I added a few records in a row and then tried to reorder them, the reorderlist got really funky and confused and things started falling out of order.
If I add a null, then the items won't reorder at all - they just snap back in place on the screen.
One more option I tried was putting the Insert screen (see screenshot below) into the InsertItemTemplate of the reorderlist. When you add new rows through this template, the SortOrderID is automatically calculated for you. Brilliant, right? Not exactly. Once I'm in the template I can't access some of the controls, like the dropdown list I use to select a category for the new item.
I know I am not the only person who is doing this. When I google this issue, so many people are connecting their SQL Datasource to a Reorderlist, and I have to believe that they are adding new records to those databases.
Please, if you have any words of wisdom for me, I am all ears....
I am going to post on the ASP.Net message boards, and maybe EXPERT SEXCHANGE.com too. Yes, Jeff, I threw that one in there for you! Jeff likes to point out that Experts Exchange actually spells Expert Sexchange.
Thanks!

I'm stuck on this ASP.Net application. I have a few controls on the page that all link up to 2 tables. The one I am stuck on is the Ajax Reorderlist. The Reorderlist is a list that has drag-and-drop capability. You can drag each item in the list and reorder it. For a demo of the Reorderlist, see this link: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ReorderList/ReorderList.aspx
My reorderlist is hooked up to a SQL datasource and it displays a list of items. The client wants to be able to change the order of the items so that the items appear on the main page of the website in a particular order. At first glance, the Reorderlist seems to be just the answer.
This is my problem: how do I add new records and still be able to reorder them? I have the datasource connected to the Reorderlist and it all works great, as long as I don't add new records to the database. Here's the thing: when you set up the table that holds the items you are going to reorder, you have to add a column to the table with a datatype of INT and this column will hold the Sort Order. This column cannot contain Null values. When you drag and drop the list items on the page, the Sort Order is posted back to the server and the values in the Sort Order column of the table are updated.
So, for instance, if I have 3 items in my table and they start out like this:
| ItemID | SortOrderID |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
And if I drag and drop them, then check the table after the post-backs occur, I will see something like this:
| ItemID | SortOrderID |
|---|---|
| 1 | 3 |
| 2 | 1 |
| 3 | 2 |
Now, if I add a new record, what the heck do I put in the SortOrderID field for a value? I can't auto-increment that column for 2 reasons: #1, ItemID is already an Identity column and I can't have 2 Identity columns; and #2, the values in an identity column keep their value even if you try to reorder them - they don't update.
I could query for the largest SortOrderID value just before I insert a new record and then add "1" to it, which will give me the next available value, then insert that number into the table. But that is my last choice. It's too risky to do that -- what happens when 2 people are adding new records at the exact same time and they pull that value at exactly the same time? It'll screw up the Reorderlist and I'll get a call telling me that it's not working. And then I'll be right back where I am now.
I tried to make the default value zero (0) on inserting, which does technically work but it is extremely sloppy. When I added a few records in a row and then tried to reorder them, the reorderlist got really funky and confused and things started falling out of order.
If I add a null, then the items won't reorder at all - they just snap back in place on the screen.
One more option I tried was putting the Insert screen (see screenshot below) into the InsertItemTemplate of the reorderlist. When you add new rows through this template, the SortOrderID is automatically calculated for you. Brilliant, right? Not exactly. Once I'm in the template I can't access some of the controls, like the dropdown list I use to select a category for the new item.
I know I am not the only person who is doing this. When I google this issue, so many people are connecting their SQL Datasource to a Reorderlist, and I have to believe that they are adding new records to those databases.
Please, if you have any words of wisdom for me, I am all ears....
I am going to post on the ASP.Net message boards, and maybe EXPERT SEXCHANGE.com too. Yes, Jeff, I threw that one in there for you! Jeff likes to point out that Experts Exchange actually spells Expert Sexchange.
Thanks!



















































