Learn More





Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesPick a DAL2 column at random?Pick a DAL2 column at random?
New Post
5/19/2014 8:43 AM

Please be gentle, I'm a newbie :)

I've got the following DAL2 model for users and their question + answers. In my module the user enters their username and I want to present them with one of their questions, at random, for them to answer. However I'm not sure how to access one of these questions at random.

public class MyUser
public int RefID { get; set; }
public int MyUserRef { get; set; }
public string Username { get; set; }
public string Question1 { get; set; }
public string Question2 { get; set; }
public string Question3 { get; set; }
public string Answer1 { get; set; }
public string Answer2 { get; set; }
public string Answer3 { get; set; }
public DateTime CreatedOnDate { get; set; }
public DateTime LastModifiedOnDate { get; set; }

For testing, omitting the random part, I can just present one of the questions from my view with:

lblQuestiontoAnswer.Text = curUser.Question1;

I thought about putting all the questions and answers into a string array, then picking one of those array items at random, but got lost in the logic.

Any pointers greatly appreciated.

New Post
5/19/2014 9:06 AM
how about sth. like getDateTime().toInteger Mod 3 - it is not really random but might be sufficient for your use case.

Cheers from Germany,
Sebastian Leupold (Microsoft MVP)

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group   European Network of DotNetNuke Professionals

Speed up your DNN Websites with TurboDNN
New Post
5/19/2014 9:12 AM

I've tried using Random():

Random rand = new Random();
int rdmQuestion = rand.Next(2) + 1;

But then I'm not sure how to build my call to the properties in my curUser object to integrate that random number.

I'm wondering whether I should build a method in the Controller which returns a random question/answer pair.

New Post
5/19/2014 9:32 AM
Accepted Answer 
generally columns (and model values) with numbers in their names are poor practice and do not follow database normalization rules ( - as such you will often run into situations where you have to hack a solution to pick a particular column, when really you want to split the questions and answers into their own table and then you can pick a random row. That said, if you know you have a fixed amount of columns you can use a switch statement ( to randomly pick a column and then set a value to ensure that you then check the right answer against the right column

Buy the new Professional DNN7: Open Source .NET CMS Platform book Amazon US
New Post
5/19/2014 10:53 AM
Thanks, I'll start investigating both of those options!
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesPick a DAL2 column at random?Pick a DAL2 column at random?

These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
Try Evoq
For Free
Start Free Trial
a Demo
See Evoq Live
Need More Information?