471,089 Members | 1,126 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Displaying questions using formview for user to do

I have saved the questions using AddQuestion.aspx page i have created but i don't know how to display it and calculate their score.

this is the formview i have done, but there is some error

Expand|Select|Wrap|Line Numbers
  1. <asp:FormView ID="FormView1" runat="server" DataKeyNames="QuestionID" DataSourceID="SqlDataSource1"
  2.                     Width="151px" AllowPaging="True">
  3.                     <EditItemTemplate>
  4.                         QuestionID:
  5.                         <asp:Label ID="QuestionIDLabel1" runat="server" Text='<%# Eval("QuestionID") %>'>
  6.                         </asp:Label><br />
  7.                         Question:
  8.                         <asp:TextBox ID="QuestionTextBox" runat="server" Text='<%# Bind("Question") %>'>
  9.                         </asp:TextBox><br />
  10.                         Choice1:
  11.                         <asp:TextBox ID="Choice1TextBox" runat="server" Text='<%# Bind("Choice1") %>'>
  12.                         </asp:TextBox><br />
  13.                         Choice2:
  14.                         <asp:TextBox ID="Choice2TextBox" runat="server" Text='<%# Bind("Choice2") %>'>
  15.                         </asp:TextBox><br />
  16.                         Choice3:
  17.                         <asp:TextBox ID="Choice3TextBox" runat="server" Text='<%# Bind("Choice3") %>'>
  18.                         </asp:TextBox><br />
  19.                         Choice4:
  20.                         <asp:TextBox ID="Choice4TextBox" runat="server" Text='<%# Bind("Choice4") %>'>
  21.                         </asp:TextBox><br />
  22.                         Answer:
  23.                         <asp:TextBox ID="AnswerTextBox" runat="server" Text='<%# Bind("Answer") %>'>
  24.                         </asp:TextBox><br />
  25.                         ModuleID:
  26.                         <asp:TextBox ID="ModuleIDTextBox" runat="server" Text='<%# Bind("ModuleID") %>'>
  27.                         </asp:TextBox><br />
  28.                         <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
  29.                             Text="Update">
  30.                         </asp:LinkButton>
  31.                         <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
  32.                             Text="Cancel">
  33.                         </asp:LinkButton>
  34.                     </EditItemTemplate>
  35.                     <InsertItemTemplate>
  36.                         Question:
  37.                         <asp:TextBox ID="QuestionTextBox" runat="server" Text='<%# Bind("Question") %>'>
  38.                         </asp:TextBox><br />
  39.                         Choice1:
  40.                         <asp:TextBox ID="Choice1TextBox" runat="server" Text='<%# Bind("Choice1") %>'>
  41.                         </asp:TextBox><br />
  42.                         Choice2:
  43.                         <asp:TextBox ID="Choice2TextBox" runat="server" Text='<%# Bind("Choice2") %>'>
  44.                         </asp:TextBox><br />
  45.                         Choice3:
  46.                         <asp:TextBox ID="Choice3TextBox" runat="server" Text='<%# Bind("Choice3") %>'>
  47.                         </asp:TextBox><br />
  48.                         Choice4:
  49.                         <asp:TextBox ID="Choice4TextBox" runat="server" Text='<%# Bind("Choice4") %>'>
  50.                         </asp:TextBox><br />
  51.                         Answer:
  52.                         <asp:TextBox ID="AnswerTextBox" runat="server" Text='<%# Bind("Answer") %>'>
  53.                         </asp:TextBox><br />
  54.                         ModuleID:
  55.                         <asp:TextBox ID="ModuleIDTextBox" runat="server" Text='<%# Bind("ModuleID") %>'>
  56.                         </asp:TextBox><br />
  57.                         <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
  58.                             Text="Insert">
  59.                         </asp:LinkButton>
  60.                         <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
  61.                             Text="Cancel">
  62.                         </asp:LinkButton>
  63.                     </InsertItemTemplate>
  64.                     <ItemTemplate>
  65.                         Question
  66.                         <asp:Label ID="QuestionIDLabel" runat="server" Text='<%# Eval("QuestionID") %>'></asp:Label>:<br />
  67.                         <asp:Label ID="QuestionLabel" runat="server" Text='<%# Bind("Question") %>' Height="93px" Width="416px"></asp:Label><br /><asp:RadioButton ID="RadioButton1" runat="server" Checked='<%# Bind("Choice1") %>'
  68.                             Height="11px" Width="105px" />A:
  69.                         <asp:Label ID="Choice1Label" runat="server" Text='<%# Bind("Choice1") %>' Width="260px"></asp:Label><br /><asp:RadioButton ID="RadioButton2" runat="server" Checked='<%# Bind("Choice2") %>'
  70.                             Height="11px" Width="105px" />B:
  71.                         <asp:Label ID="Choice2Label" runat="server" Text='<%# Bind("Choice2") %>' Width="263px"></asp:Label><br /><asp:RadioButton ID="RadioButton3" runat="server" Checked='<%# Bind("Choice3") %>'
  72.                             Height="11px" Width="105px" />C:
  73.                         <asp:Label ID="Choice3Label" runat="server" Text='<%# Bind("Choice3") %>' Width="259px"></asp:Label><br /><asp:RadioButton ID="RadioButton4" runat="server" Checked='<%# Bind("Choice4") %>'
  74.                             Height="11px" Width="105px" />D:
  75.                         <asp:Label ID="Choice4Label" runat="server" Text='<%# Bind("Choice4") %>' Width="255px"></asp:Label><br />
  76.                         <asp:Label ID="AnswerLabel" runat="server" Text='<%# Bind("Answer") %>' Visible="False"></asp:Label><br />
  77.                         <asp:Label ID="ModuleIDLabel" runat="server" Text='<%# Bind("ModuleID") %>' Visible="False"></asp:Label><br />
  78.                         <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
  79.                             Text="Edit" Visible="False"></asp:LinkButton>
  80.                         <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
  81.                             Text="Delete" Visible="False"></asp:LinkButton>
  82.                         <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
  83.                             Text="New" Visible="False"></asp:LinkButton>
  84.                     </ItemTemplate>
  85.                 </asp:FormView>
  86.  
Error!

Expand|Select|Wrap|Line Numbers
  1. Conversion from type 'DBNull' to type 'Boolean' is not valid. 
  2. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  3.  
  4. Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Boolean' is not valid.
  5.  
  6. Source Error: 
  7.  
  8.  
  9. Line 80:                         Question
  10. Line 81:                         <asp:Label ID="QuestionIDLabel" runat="server" Text='<%# Eval("QuestionID") %>'></asp:Label>:<br />
  11. Line 82:                         <asp:Label ID="QuestionLabel" runat="server" Text='<%# Bind("Question") %>' Height="93px" Width="416px"></asp:Label><br /><asp:RadioButton ID="RadioButton1" runat="server" Checked='<%# Bind("Choice1") %>'
  12. Line 83:                             Height="11px" Width="105px" />A:
  13. Line 84:                         <asp:Label ID="Choice1Label" runat="server" Text='<%# Bind("Choice1") %>' Width="260px"></asp:Label><br /><asp:RadioButton ID="RadioButton2" runat="server" Checked='<%# Bind("Choice2") %>'
  14.  
Thanks for the help, any help would be appreciated.
Mar 27 '09 #1
6 1987
tlhintoq
3,525 Expert 2GB
I have saved the questions using AddQuestion.aspx page i have created but i don't know how to display it and calculate their score.

this is the formview i have done, but there is some error
What are you talking about? There is no context in this statement for anyone to understand what you're doing.

The first step from anyone here is to take your code and try to reverse engineer your intention before they can even try to figure out the problem or solution. In the future please take an extra 5 minutes to properly document your situation. Please visit the Posting Guidelines for tips on how to ask questions to get the best help.

As for this post... Let's walk it through from the error, backward to the code causing the problem.
but there is some error
Nice job on including this detail. So many people don't. :-)
Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Boolean' is not valid.
Someplace in your code you tried to set a Boolean equal to DBNull, instead of setting it equal to either true or false: the only options for a Boolean.
<asp:RadioButton ID="RadioButton1" runat="server" Checked='<%# Bind("Choice1") %>
You have narrowed it down to these controls. In trying to set the checked state you only have two choices: True or false. But your DB returned null which is caused the error.

My first thought is that "Coice1" and "Choice2" in the dB don't have any values. You might want to make sure these fields don't allow nulls to be answers. Either that or you have to check or your server responses before you use them, to make sure what you receive is what you *expect* to receive. In the real world you should never code based on the idea that everything is right. Work on the premise that everything is wrong/bad/corrupt. If your database gets corrupted a year from today and Choice1 value became "Alaska" instead of boolean true then your code breaks.
Mar 27 '09 #2
Oh sorry..i actually meant that i have created this AddQuestion.aspx so that i can save questions in the database and then retrieve it from the database and display in the ViewQuestion.aspx for the users to do it. Thus, i am now doing the ViewQuestion.aspx using formView and because i have never use formview before, i'm not farmiliar with it.

Thanks alot for the help, i will try to solve it first, if i have further questions, i'll post again.
Mar 27 '09 #3
Hi,
I have solved the above problem but i have another problem, they are able to select all the choices.
Attached Images
File Type: jpg question.jpg (6.5 KB, 167 views)
Mar 27 '09 #4
tlhintoq
3,525 Expert 2GB
Yep. That looks like a problem.
Mar 27 '09 #5
So how can i solve it? and record the score of the user?
Mar 27 '09 #6
tlhintoq
3,525 Expert 2GB
That's where the "trial and error" part of learning comes in.
In a C# windows form application all radio dials that are part of a Group container are automatically made part of the same group and only allowed to select one.
I think in HTML you can provide a group name for such controls to do the same thing. You need to research how it is done in ASP. (Google for ASP radio dial) as a start.



Its a Q&A program.. So what do you need to do the job?
Questions
Answers
Answer key
Your DB is going to need to know the correct answer as well as the user answer. (but don't display it)
If the user answer is right, then the score keeping variable increments.
Mar 27 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Richard Carpenter | last post: by
2 posts views Thread by Kelly | last post: by
reply views Thread by ThePurpleCat | last post: by
12 posts views Thread by brwalias | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.