Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Online Quiz wanted to show questions in random order

Online Quiz wanted to show questions in random order

Scheduled Pinned Locked Moved ASP.NET
databasesql-serversysadmintutoriallounge
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chitra81
    wrote on last edited by
    #1

    Hi I have quiz project running online. and i am using sql server 2005 as backend. The controls i am using to show questions is detailsview. I need to show questions in random order. I don't know how to do it. If somebody knows pls tell me. I am in great trouble.

    J 1 Reply Last reply
    0
    • C chitra81

      Hi I have quiz project running online. and i am using sql server 2005 as backend. The controls i am using to show questions is detailsview. I need to show questions in random order. I don't know how to do it. If somebody knows pls tell me. I am in great trouble.

      J Offline
      J Offline
      John ph
      wrote on last edited by
      #2

      to select the records in random order, you can use "order by NewId()" in the select statement. something like this select * from tblQuestions order by NewID() bind the resultant set to the grid view


      Regards
      John


      V 1 Reply Last reply
      0
      • J John ph

        to select the records in random order, you can use "order by NewId()" in the select statement. something like this select * from tblQuestions order by NewID() bind the resultant set to the grid view


        Regards
        John


        V Offline
        V Offline
        Virendrak
        wrote on last edited by
        #3

        Use , NewID()

        Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...

        E 1 Reply Last reply
        0
        • V Virendrak

          Use , NewID()

          Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...

          E Offline
          E Offline
          e wrench
          wrote on last edited by
          #4

          Another way to do that is to load the questions into a datatable. Create an integer array from 0 to datatable row count. Then use the Fisher-Yates algorithm to shuffle the array. Clone the original datatable and then load rows into the cloned datatable using the order of the shuffled array. Alternatively you could have a question order field in the question database and shuffle the numbers in the datatable. Finally bind the datatable to the detailsview grid. Cheers.

          Mike Rehner IT Teacher Northeast Career Center Columbus OH 43219

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups