Last post Jan 07, 2015 05:40 AM by wavemaster
Jan 05, 2015 10:22 AM|mdehghani|LINK
I'm trying to design an online quiz project using asp.net web pages and SQL. I've already created my Questions database table with several columns containing QuestionId, Question, 1stChoice, 2ndChoice, 3rdChoice, 4thChoice, and CorrectAnswer. I've also created
my student answers table containing StudentId, Q1, Q2, Q3, ... Q10.
now for my quiz page I need a code to extract the 10 questions (all at once. not wizard style) along with their 4 choices and display choices as radio buttons and when the logged in user answers the question and clicks the submit button i need the information
to be stored in the answers table regarding each users row.
I also have to mention that the user should have the option not to answer some questions so I also have to store the unanswerd questions as null. is this possible with radios? or I have to add another radio button stating "skip question" or should i totally
chose another approach? how is this thing done? thanks..
Jan 05, 2015 11:00 AM|Mikesdotnetting|LINK
This article should give you some clues about managing radios for your scenario: http://www.mikesdotnetting.com/article/218/managing-checkboxes-and-radios-in-asp-net-razor-web-pages
Radios would be the way I would do this, by the way.
Jan 05, 2015 11:04 AM|wavemaster|LINK
That is all possible.
Check out one of these surveys to see how they do that. Think I remember seeing check boxes, but I am not sure.
I would recommend that you add to your table the no answer scenario. It will be easier to display and manage later.
Jan 06, 2015 01:26 PM|mdehghani|LINK
which surveys? and whats the no answer scenario??
Jan 06, 2015 01:40 PM|mdehghani|LINK
I've read that article before Mike.. surely useful.. but not exactly what I'm looking for.. I Guess web pages doesn't have enough resources after all.. only 2 main tutorials on Asp.net website.. the movies website which is so simple that can be learned in
simply describing the proper way of data handling??
Jan 06, 2015 02:16 PM|Mikesdotnetting|LINK
What aspect of data handling are you struggling with?
Jan 06, 2015 02:22 PM|mdehghani|LINK
collecting user info (logged in users of course) by radio forms and storing in a table (along with their user ids)
Jan 06, 2015 02:37 PM|Mikesdotnetting|LINK
It's pretty basic stuff in all honesty and covered in a combination of the article I linked to and the basic web pages tutorials you have already found. Short of writing a fully working example of a quiz project for you, I'm not sure what other help can
Jan 06, 2015 02:48 PM|mdehghani|LINK
yes .. it seems basic to me also.. but the first tutorial doesn't involve handling individual user input at all.. and the second one is too confusing.. I've decided to read a textbook i recently found about web pages and webmatrix ... i hope i can get on
track as soon as possible..
Jan 06, 2015 03:31 PM|wavemaster|LINK
Why do you say the soccer websites is officialy-broken?
Anyway, start with the starter site template.
Create your tables.
Create your form.
Jan 06, 2015 03:57 PM|mdehghani|LINK
I call it broken because the example code can't be downloaded.. the link is broken.. I downloaded it with the help of Mike.. by the way .. i know how to make a table .. i know how to make a form.. i just don't know how to pass the values chosen by the user
to the table..
Jan 06, 2015 04:38 PM|Mikesdotnetting|LINK
The data tutorial should help you: http://www.asp.net/web-pages/overview/data
Jan 06, 2015 04:46 PM|mdehghani|LINK
it quite helps but it doesn't directly involve userId.. I'll give it a try anyway..
Jan 06, 2015 05:04 PM|Mikesdotnetting|LINK
The security tutorials will cover that.
Jan 06, 2015 05:19 PM|mdehghani|LINK
I'm looking for a resource that fully explains the following lines and functions .. I'm sure it has not been discussed in the mentioned articles..
// Check if the user has logged on to the site.
// Get the ID of the current logged on user.
int userId = WebSecurity.CurrentUserId;
// Check if this is a postback that requires the data to be updated.
// Check if user has a row in the MemberRides table for this match.
var existingRow = db.Query("SELECT * FROM MemberRides "
+ "WHERE MemberId = @0 AND MatchId = @1",
if (existingRow.Count > 0)
// Update the existing row in the MemberRides table.
rowsAffected = db.Execute("UPDATE MemberRides "
+ "SET SeatsAvailableOrRequired = @0 "
+ "WHERE MemberId = @1 AND MatchId = @2",
ridesValue, userId, match.matchId);
// Add a new row to the MemberRides table.
rowsAffected= db.Execute("INSERT INTO MemberRides(MemberId, "
+ "MatchId, SeatsAvailableOrRequired) VALUES (@0, @1, @2)",
userId, match.matchId, ridesValue);
Jan 06, 2015 05:50 PM|wavemaster|LINK
Jan 06, 2015 06:01 PM|mdehghani|LINK
I found this link offending mr. Wavemaster! I already know what google is! and that wasn't what i was looking for!
Jan 06, 2015 06:39 PM|wavemaster|LINK
Simply helping you along on your education path.
You did ask non specific questions. Our time has value too, so narrow things down and be specific about your question.
This is what you said:
// Check if the user has logged on to the site.
What is your question?
Jan 07, 2015 01:58 AM|Mikesdotnetting|LINK
I would have thought the comments in the code do a pretty good job of explaining what each code section does. Beyond that, as wavemaster said, if you have specific questions about specific lines of code, please ask them.
Jan 07, 2015 04:21 AM|mdehghani|LINK
OK.. sorry to take your valuable time.. I'll do a lot of study and come back with more specific questions..
Jan 07, 2015 05:40 AM|wavemaster|LINK
Another thing you could consider is running the code through Visual Studio in debug mode. You can see what is going on.