0

I have a bank of 100 questions in a database. I T-SQL has been written by someone else to pick 30 unique questions out of the 100 in a random fashion. (the query was tested and result were as expected)

Now, I need those 30 unique records (the random sample) to be displayed one at a time. basically showing the next record when the user clicks a button (next for instance).

Currently, I have a sqlDataSource with its ID assigned to a DetailsView in aspx page. I have a button that basically increments the DetailsView.PageIndex.

I found that the detailsView keeps reexecuting the sqlCommand in the sqlDataSource resulting in repeated questions. I found out by tracing the sql.

What am I doing wrong or Which data control to use and any other suggestions and if possible refer me to an example please?

Thank you so much!

venerik
  • 5,766
  • 2
  • 33
  • 43
Abdul
  • 9
  • 5
  • Are you wanting to only ask the database once for 30 questions and never ask the database again while the user moves through the list of questions? If so, then you need to cache the 30 items and then ask the cache for the next one, I would suggest a List for that stored in Session cache. – Karl Anderson Jun 19 '13 at 20:10
  • @Karl would it take 30 records? or any number of records? is it reliable for that? – Abdul Jun 19 '13 at 21:29
  • You could take all 30 or any part you wanted, I assume you wanted all of them so that the user's experience is extremely snappy when switching between records, because it is working at memory speed on the server instead of calling to the database for more records. Efficiency-wise, the custom paging solution proposed by Azzi is a better approach as you are reducing the initial load time, reducing the amount of memory being used as there is nothing stored in session cache and it is relatively quick as long as you keep the page size low (i.e. 5 to 10 records). You have options. :-) – Karl Anderson Jun 20 '13 at 01:36
  • @Karl Thanks Karl but again, GridView is no good for my application since i need the fields to be displayed in rows ... i.e. question, then option1, option2, .. etc. – Abdul Jun 20 '13 at 07:04

1 Answers1

1

I would suggest trying the GridView Control. You can use the controls paging ability to decide how much of your record set to display (without having to re-execute the sqlCommand).

Here are some good examples of how to use the GridView control.

Zzz
  • 2,927
  • 5
  • 36
  • 58
  • This is obviously better than his built-in paging query of all 100 items every time, but this does not satisfy the "without reissuing the query" part of his question. If I am being too literal, then my apologies. – Karl Anderson Jun 19 '13 at 20:12
  • @Karl Why would binding the record set to the a GridView and then setting the page limit to 1 not satisfy "without reissuing the query" criteria? – Zzz Jun 19 '13 at 20:18
  • Because I am thinking he means "ask for the 30 records once and never ask again". Again I am postulating here. I am not saying that your answer would not work, but just trying to get the poster to clarify what the "without reissuing query" statement actually means. – Karl Anderson Jun 19 '13 at 20:21
  • @Azzi Thanks both. Problem with this is that i cannot display them in rows fashion. that is questionField then, option1, option2, option3. so this is how i want them to be displayed. not in columns. – Abdul Jun 19 '13 at 21:27