delete data, then shift its number....

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2007
Posts: 34
Reputation: shy_wani is an unknown quantity at this point 
Solved Threads: 0
shy_wani shy_wani is offline Offline
Light Poster

delete data, then shift its number....

 
0
  #1
Apr 29th, 2007
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..
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

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

 
0
  #2
May 2nd, 2007
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.
  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. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC