ReorderList Delete problems in ASP.Net and VB

Posted on 2008-11-18
Last Modified: 2013-12-26
I have a working ReorderList on one of my webpages that displays questions in a survey. The item template contains two labels, one for the QuestionNumber (which is also the SortOrderField specified in the ReorderList control), and the QuestionText. I can reorder and insert items with no problems -- those features are functioning as expected.

However, when I implement the Delete functionality, it does delete a question, but it doesn't renumber the QuestionNumber. For example, if I have 4 questions (with question numbers 1 thru 4), and I delete question 2, I'm left with the question numbers 1, 3, and 4. This is probably by design, but does anyone know of any easy way to automatically renumber the items so that they would be 1, 2, and 3 instead of 1, 3, and 4?  I noticed that if I start dragging and dropping the remaining questions, they will eventually get reordered the way that they should be, but the user isn't going to want to do that.

Any ideas?
Question by:jacksonm1234
    LVL 16

    Accepted Solution

    You are probably best off maintaining sort order on addition and deletion.

    For instance, your DeleteCommand should look something like this.  It determines that the Question exists, and hasn't been reordered by anyone else since you selected it, then attempts to delete the record, followed by renumbering all questions with higher values.  Just in case anything goes wrong with that (eg: records locked on you, et cetera) it will rollback on an exception.
    IF (EXISTS (SELECT 1 FROM Questions WHERE QuestionID=@QuestionID AND QuestionNumber=@QuestionNumber)) 
            DELETE FROM Questions WHERE QuestionID=@QuestionID AND QuestionNumber=@QuestionNumber; 
            UPDATE Questions SET QuestionNumber=QuestionNumber - 1 WHERE QuestionNumber > @QuestionNumber;
        END TRY 
        BEGIN CATCH 
        END CATCH

    Open in new window

    LVL 2

    Author Closing Comment

    This was exactly what I needed. I just wasnt sure how to do this manually. THANK YOU!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now