473,701 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying questions using formview for user to do

4 New Member
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

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>

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. 
  4. Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Boolean' is not valid.
  6. Source Error: 
  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") %>'
Thanks for the help, any help would be appreciated.
Mar 27 '09 #1
6 2276
3,525 Recognized Expert Specialist
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.
Mar 27 '09 #2
4 New Member
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.
Mar 27 '09 #3
4 New Member
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, 192 views)
Mar 27 '09 #4
3,525 Recognized Expert Specialist
Yep. That looks like a problem.
Mar 27 '09 #5
4 New Member
So how can i solve it? and record the score of the user?
Mar 27 '09 #6
3,525 Recognized Expert Specialist
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?
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

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

Similar topics

by: Luqman | last post by:
How can I display any field value in textbox of sqldatasource using VS.Net 2005 ? Say : Dim x as new AccessDataSource X.connectionstring="Data source="D:\mydb.mdb" X.Selectcommand="Select CompanyName from customers" Textbox1.text= ??? <-------- I need to display CompanyName Field in this textbox, how can I ?
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the sqldatasource of the formview. If i put this textboxes outside the table everything works well, but as soon as i put them inside the table (in order to organize the layout in the right way) they doesn't work. They works only as eval() and not bind()...
by: Richard Carpenter | last post by:
I understand how to use a dropdown list control to display the associated description value for a foreign key in a parent rather than the key itself, but I don't like having to disable the control when I want to prevent editing (simply displaying in the display template of a datalist or detailview control, for example). I've not been able to find a way to edit the disabled color of the dropdown list, so it appears very washed out - just...
by: Kelly | last post by:
I'm fairly new to ASP.NET2, but I have an ASP 3.0 background, and I've been experimenting with the DataSource and FormView widgets. I wound up having some questions along the way which I hope you all can address to help me understand events with these better. I've been reading up on inserted/inserting also deleted/deleting, but where is it better to run call those events from via formview or datasource? Also, I have been trying to...
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1"> <EditItemTemplate>
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1"> <EditItemTemplate>
by: ThePurpleCat | last post by:
Hi, I'm a newbie to ASP.NET programming but not to Visual Studio. I'm having trouble getting my Master-Details page to work. I have a page enabled GridView which is linked to a FormView control through an objectdatasource. The paging on my GridView works fine except that when I change the page the FormView does not update. I tried setting the selectedindex to 0 in the GridView's PageIndexChanged event and manually binding the formview...
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a formview for inserting and editing the records. when a user clicks on one of the records in the...
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that variable in the url. I would like that variable to trigger a stored and
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.