[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

ReorderList Delete problems in ASP.Net and VB

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?
0
jacksonm1234
Asked:
jacksonm1234
1 Solution
 
GreymanMSCCommented:
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)) 
BEGIN 
    BEGIN TRANSACTION BEGIN TRY
        DELETE FROM Questions WHERE QuestionID=@QuestionID AND QuestionNumber=@QuestionNumber; 
        UPDATE Questions SET QuestionNumber=QuestionNumber - 1 WHERE QuestionNumber > @QuestionNumber;
        COMMIT TRANSACTION
    END TRY 
    BEGIN CATCH 
        ROLLBACK TRANSACTION 
    END CATCH
END;

Open in new window

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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now