943,537 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 1211
  • ASP.NET RSS
Apr 29th, 2007
0

delete data, then shift its number....

Expand Post »
hi..good day to all

i have a table: Question
atttributes: SurveyID(FK),QuestionID(PK),QuestionNum,Question and QuestionTypeID

if i have a dropdown list specifying the list of QuestionNum in my ASPX page and a delete button besides the list, how can i delete one QuestionNum? after delete, how can i shift the Question Number without changing the QuestionID?

examples: SurveyID=140 has QuestionNum=10
so, QuestionNum would be from 1-10...
if i were to delete QuestionNum=3...i want to delete QuestionNum=3 and at the same time, i want other QuestionNum after the deleted ones (means, QuestionNum=4 to QuestionNum=10) to shift their value...means...Question=4 is now QuestionNum=3,QuestionNum=5 to be QuestionNum=4, and so on...

how can i perform this? please help me..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
shy_wani is offline Offline
34 posts
since Mar 2007
May 2nd, 2007
0

Re: delete data, then shift its number....

no easy way sorry.
You have to get an array of datarows where the surveyid = the surveyid of the row you deleted (140 in your example) and sorted on the question number column. Then run through each one and redo the question number using a count
e.g.
ASP.NET Syntax (Toggle Plain Text)
  1. DataRow[] rows = QuestionTable.Select("SurveyID = " + deletedrow["surveyid"], "QuestionNum asc");
  2. for (int i=0; i < rows.length; i++)
  3. {
  4. rows[i]["QuestionNum"] = i+1;
  5. }
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Generate Html from VB.net
Next Thread in ASP.NET Forum Timeline: Please help me...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC