I have a stored procedure that generates the questions randomly and inserting them into a temp table for displaying them in a GridView.
Further to this I would like to retrieve the question followed by a radio button against each option stored in four columns so that user can select one option among these.
How do I do this?
I would like to use the option select to further evaluate the answer.
Hope I have made myself clear.
Any guidance will be of great help.
Thanks
(eg)
1. One byte equals to ---Col1 in table
optA 2 bits----Col2 in table
optB 4 bits----Col3
optC 8 bits----Col4
OptD 16 bits--Col5
Answer 16 bits--Col6
my stored procedure in sql server 2000 is as below
Expand|Select|Wrap|Line Numbers
- ALTER PROCEDURE [dbo].[quesRand] (@NO_ques int)
- -- Add the parameters for the stored procedure here
- AS
- BEGIN
- set NOCOUNT ON
- DECLARE @intFlag INT
- DECLARE @random INT
- DECLARE @upper INT
- DECLARE @lower INT
- SET @intFlag = 1
- set @lower=1
- set @upper=100
- create table #test4 (cd_no int,cd_name nvarchar(50),date_received smalldatetime,
- shipped_with_remarks nvarchar(50))
- WHILE (@intFlag <=@NO_ques)
- BEGIN
- select @random=Round(((@upper-@lower-1))*RAND()+@lower,0)
- PRINT @random
- insert into #test4
- select * from science where cd_no=@random
- SET @intFlag = @intFlag + 1
- END
- select * from #test4
- END
I am using Visual studio 2005 and .aspx page is as below
Expand|Select|Wrap|Line Numbers
- %@ Page Language="C#" AutoEventWireup="true" debug="true" CodeFile="Ques.aspx.cs" Inherits="_Default" %>
- <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Software CD search</title>
- <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
- <script type="text/javascript">
- $(function () {
- $('#txtNo_ques').keydown(function (e) {
- if (e.shiftKey || e.ctrlKey || e.altKey) {
- e.preventDefault();
- } else {
- var key = e.keyCode;
- if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
- e.preventDefault();
- }
- }
- });
- });
- </script>
- </head>
- <body >
- <form id="form1" action="Ques.aspx.cs" runat="server">
- <div align=center>
- <asp:Label ID="lblNo_ques" runat="server" Text="Enter the no. of questions"></asp:Label>
- <asp:TextBox ID="txtNo_ques" runat="server"></asp:TextBox>
- <asp:RequiredFieldValidator ID="Validate_No_ques" runat="server" ControlToValidate="txtNo_ques"
- ErrorMessage="Please Enter the no. of questions!"></asp:RequiredFieldValidator>
- </div>
- <div align="center" style="margin:20px;" >
- <asp:Button ID="genQues" runat="server" Text="Generate & View" OnClick="genQues_Click" />
- </div>
- <div>
- </div>
- <hr />
- <div align="center" >
- <asp:GridView ID="dgv1" runat="server" BackColor="LightSteelBlue" BorderColor="Crimson" BorderStyle="Double" BorderWidth="2px" ForeColor="Black" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True">
- <EditRowStyle BackColor="Teal" BorderColor="#C00000" BorderWidth="3px" />
- <AlternatingRowStyle BackColor="InactiveCaption" BorderColor="Green" />
- <RowStyle BackColor="#FFE0C0" BorderColor="#004040" BorderStyle="Ridge" BorderWidth="3px" />
- <HeaderStyle BackColor="Thistle" BorderColor="PaleGreen" BorderStyle="Dashed" />
- </asp:GridView>
- </div>
- </form>
- </body>
- </html>
My code behind file Ques.aspx.cs is as follows
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- using System.Collections.Generic;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void genQues_Click(object sender, EventArgs e)
- {
- string constring = ConfigurationManager.AppSettings.Get("con").ToString();
- SqlConnection conn = new SqlConnection(constring);
- conn.Open();
- SqlCommand check = new SqlCommand("quesRand", conn);
- check.CommandType = CommandType.StoredProcedure;
- check.Parameters.Add(new SqlParameter("@NO_ques", SqlDbType.Int));
- check.Parameters["@NO_ques"].Value = txtNo_ques.Text;
- SqlDataAdapter da = new SqlDataAdapter(check);
- DataSet ds = new DataSet();
- da.Fill(ds);
- this.dgv1.DataSource = ds.Tables[0].DefaultView;
- dgv1.DataBind();
- conn.Close();
- }