Displaying questions using formview for user to do

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IReallyNeedHelp
    New Member
    • Mar 2009
    • 4

    #1

    Displaying questions using formview for user to do

    I have saved the questions using AddQuestion.asp x 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

    Code:
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="QuestionID" DataSourceID="SqlDataSource1"
                        Width="151px" AllowPaging="True">
                        <EditItemTemplate>
                            QuestionID:
                            <asp:Label ID="QuestionIDLabel1" runat="server" Text='<%# Eval("QuestionID") %>'>
                            </asp:Label><br />
                            Question:
                            <asp:TextBox ID="QuestionTextBox" runat="server" Text='<%# Bind("Question") %>'>
                            </asp:TextBox><br />
                            Choice1:
                            <asp:TextBox ID="Choice1TextBox" runat="server" Text='<%# Bind("Choice1") %>'>
                            </asp:TextBox><br />
                            Choice2:
                            <asp:TextBox ID="Choice2TextBox" runat="server" Text='<%# Bind("Choice2") %>'>
                            </asp:TextBox><br />
                            Choice3:
                            <asp:TextBox ID="Choice3TextBox" runat="server" Text='<%# Bind("Choice3") %>'>
                            </asp:TextBox><br />
                            Choice4:
                            <asp:TextBox ID="Choice4TextBox" runat="server" Text='<%# Bind("Choice4") %>'>
                            </asp:TextBox><br />
                            Answer:
                            <asp:TextBox ID="AnswerTextBox" runat="server" Text='<%# Bind("Answer") %>'>
                            </asp:TextBox><br />
                            ModuleID:
                            <asp:TextBox ID="ModuleIDTextBox" runat="server" Text='<%# Bind("ModuleID") %>'>
                            </asp:TextBox><br />
                            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                                Text="Update">
                            </asp:LinkButton>
                            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                Text="Cancel">
                            </asp:LinkButton>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            Question:
                            <asp:TextBox ID="QuestionTextBox" runat="server" Text='<%# Bind("Question") %>'>
                            </asp:TextBox><br />
                            Choice1:
                            <asp:TextBox ID="Choice1TextBox" runat="server" Text='<%# Bind("Choice1") %>'>
                            </asp:TextBox><br />
                            Choice2:
                            <asp:TextBox ID="Choice2TextBox" runat="server" Text='<%# Bind("Choice2") %>'>
                            </asp:TextBox><br />
                            Choice3:
                            <asp:TextBox ID="Choice3TextBox" runat="server" Text='<%# Bind("Choice3") %>'>
                            </asp:TextBox><br />
                            Choice4:
                            <asp:TextBox ID="Choice4TextBox" runat="server" Text='<%# Bind("Choice4") %>'>
                            </asp:TextBox><br />
                            Answer:
                            <asp:TextBox ID="AnswerTextBox" runat="server" Text='<%# Bind("Answer") %>'>
                            </asp:TextBox><br />
                            ModuleID:
                            <asp:TextBox ID="ModuleIDTextBox" runat="server" Text='<%# Bind("ModuleID") %>'>
                            </asp:TextBox><br />
                            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                Text="Insert">
                            </asp:LinkButton>
                            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                Text="Cancel">
                            </asp:LinkButton>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            Question
                            <asp:Label ID="QuestionIDLabel" runat="server" Text='<%# Eval("QuestionID") %>'></asp:Label>:<br />
                            <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") %>'
                                Height="11px" Width="105px" />A:
                            <asp:Label ID="Choice1Label" runat="server" Text='<%# Bind("Choice1") %>' Width="260px"></asp:Label><br /><asp:RadioButton ID="RadioButton2" runat="server" Checked='<%# Bind("Choice2") %>'
                                Height="11px" Width="105px" />B:
                            <asp:Label ID="Choice2Label" runat="server" Text='<%# Bind("Choice2") %>' Width="263px"></asp:Label><br /><asp:RadioButton ID="RadioButton3" runat="server" Checked='<%# Bind("Choice3") %>'
                                Height="11px" Width="105px" />C:
                            <asp:Label ID="Choice3Label" runat="server" Text='<%# Bind("Choice3") %>' Width="259px"></asp:Label><br /><asp:RadioButton ID="RadioButton4" runat="server" Checked='<%# Bind("Choice4") %>'
                                Height="11px" Width="105px" />D:
                            <asp:Label ID="Choice4Label" runat="server" Text='<%# Bind("Choice4") %>' Width="255px"></asp:Label><br />
                            <asp:Label ID="AnswerLabel" runat="server" Text='<%# Bind("Answer") %>' Visible="False"></asp:Label><br />
                            <asp:Label ID="ModuleIDLabel" runat="server" Text='<%# Bind("ModuleID") %>' Visible="False"></asp:Label><br />
                            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                                Text="Edit" Visible="False"></asp:LinkButton>
                            <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                                Text="Delete" Visible="False"></asp:LinkButton>
                            <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                                Text="New" Visible="False"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:FormView>
    Error!

    Code:
    Conversion from type 'DBNull' to type 'Boolean' is not valid. 
    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. 
    
    Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Boolean' is not valid.
    
    Source Error: 
    
    
    Line 80:                         Question
    Line 81:                         <asp:Label ID="QuestionIDLabel" runat="server" Text='<%# Eval("QuestionID") %>'></asp:Label>:<br />
    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") %>'
    Line 83:                             Height="11px" Width="105px" />A:
    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") %>'
    Thanks for the help, any help would be appreciated.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    I have saved the questions using AddQuestion.asp x 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.InvalidC astException: 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:RadioButto n ID="RadioButton 1" 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.

    Comment

    • IReallyNeedHelp
      New Member
      • Mar 2009
      • 4

      #3
      Thanks

      Oh sorry..i actually meant that i have created this AddQuestion.asp x so that i can save questions in the database and then retrieve it from the database and display in the ViewQuestion.as px for the users to do it. Thus, i am now doing the ViewQuestion.as px 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.

      Comment

      • IReallyNeedHelp
        New Member
        • Mar 2009
        • 4

        #4
        Hi,
        I have solved the above problem but i have another problem, they are able to select all the choices.
        Attached Files

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Yep. That looks like a problem.

          Comment

          • IReallyNeedHelp
            New Member
            • Mar 2009
            • 4

            #6
            So how can i solve it? and record the score of the user?

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              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.

              Comment

              Working...