There will be some 20 questions and for each question there will be 4
choices.what i want to do is to select multiple answers by clicking the
checkbox. i m using asp.net,vb.net
pls help me
we have written the code using radio button for selecting single
item.but we want to replace it with checkbox to select multiple items.
the code using radio button is given below .pls correct it with
checkbox
Imports System.Data
Imports System.Data.SqlClient
Imports ELearning.LAIDBC
Public Class Test
Inherits System.Web.UI.Page
Public ds As New DataSet()
Public ds1 As New DataSet()
Public ds2 As New DataSet()
Public Score, Answered As Integer
Private ConDB As New ELearning.LAIDBC()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Session("Log") = Nothing Then
Response.Redirect("frmLogin.aspx")
End If
If Not IsPostBack Then
Try
Session("Course") = Session("URL2")
Session("Id") = "reshm-001"
Session("CandId") = "00000001"
'Response.Write(Session("Id"))
'Response.End()
Session("TotScore") = Nothing
Dim count1, str11 As String
ds1 = New DataSet()
ConDB.OpenConnection()
ds1 = ConDB.ExecuteSPReturnDS("ELS_ExecuteQuery",
"select count(f_UserId) from tbl_Score where f_UserId='" &
(Session("CandId")) & "' and f_courseid='" & Session("Id") & "' ")
ConDB.CloseConnection()
count1 = ds1.Tables(0).Rows(0)(0)
str11 = "select count(f_UserId) from tbl_Score where
f_UserId='" & (Session("CandId")) & "' and f_courseid='" &
Session("Id") & "'"
'Response.Write(str11)
'Response.End()
If count1 < 3 Then
' Response.Write(str11 & "," & count1)
ds2 = New DataSet()
Dim count2 As Integer
ConDB.OpenConnection()
ds2 = ConDB.ExecuteSPReturnDS("ELS_ExecuteQuery",
"select count(f_UserId) from tbl_Score where f_UserId='" &
(Session("CandId")) & "' and f_result='P'")
count2 = ds2.Tables(0).Rows(0)(0)
Response.Write(count2)
ConDB.CloseConnection()
If count2 > 0 Then
Session("msg") = "You have already passed for
the test"
Response.Redirect("frmChance.aspx")
Else
Dim qrstr As String
Dim NoOfQuestionsToDisplay As Integer
Dim Mstring As String
Dim TotalNoOfQuestions As Integer
courseidselect()
Try
NoOfQuestionsToDisplay = txtNoOfqns.Text
Session("NoOfQuestionsToDisplay ") =
txtNoOfqns.Text
ds = New DataSet()
ConDB.OpenConnection()
ds =
ConDB.ExecuteSPReturnDS("ELS_ExecuteQuery", "select count(*) from
tbl_Question where f_CourseId='" & Session("Id") & "'")
ConDB.CloseConnection()
TotalNoOfQuestions =
ds.Tables(0).Rows(0)(0)
Session("TotQns") = TotalNoOfQuestions
Catch ex As Exception
Response.Write(ex.Message)
End Try
If TotalNoOfQuestions < NoOfQuestionsToDisplay
Then
Response.Write("<Script
language='javascript'> alert('Contact the Administrator')</Script>")
If Session("Category") = "Admin" Then
Response.Redirect("frmAdminHome.aspx")
ElseIf Session("Category") = "Author" Then
Response.Redirect("frmAuthorHome.aspx")
ElseIf Session("Category") = "Client" Then
Response.Redirect("frmClientHome.aspx")
ElseIf Session("Category") = "User" Then
Response.Redirect("frmUserHome.aspx")
End If
Exit Sub
End If
Mstring = GenerateRandomQn(TotalNoOfQuestions,
NoOfQuestionsToDisplay)
Displayqns(Mstring)
Dim P As Integer, mcntr As Label
For P = 0 To DataGrid1.Items.Count - 1
mcntr =
CType(DataGrid1.Items(P).Cells(0).FindControl("qnu mber"), Label)
mcntr.Text = P + 1
Next
End If
Else
Session("msg") = "Sorry Your Chances are over"
Response.Redirect("frmChance.aspx")
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End If
End Sub
Sub Displayqns(ByVal Mstring As String)
Try
Dim str3, str4 As String
'Get questions
ds = New DataSet()
str4 = "select
f_QuestionNo,f_Question,f_choice1,f_choice2,f_choi ce3,f_choice4,f_Answer
from tbl_Question where f_CourseId='" & Session("Id") & "' and
f_QuestionNo in(" & Mstring & ")"
ConDB.OpenConnection()
ds = ConDB.ExecuteSPReturnDS("ELS_ExecuteQuery", str4)
ConDB.CloseConnection()
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub courseidselect()
Try
Dim TotalNoOfQuestions As Integer
Dim da As New SqlDataAdapter()
Dim dr As SqlDataReader
Dim ds As New DataSet()
Dim ds1 As New DataSet()
Dim NoOfQuestionsToDisplay As Integer
ConDB.OpenConnection()
Dim strSql As String = "select
f_CourseId,f_CourseName,f_NoOfQuestions,f_TimeDura tion from tbl_Course
where f_courseid='" & Session("Id") & "'"
ds = ConDB.ExecuteSPReturnDS("ELS_ExecuteQuery", strSql)
ConDB.CloseConnection()
lblCourse.Text = ds.Tables(0).Rows(0)(1)
txtNoOfqns.Text = ds.Tables(0).Rows(0)(2)
txtduration.Text = ds.Tables(0).Rows(0)(3)
Session("TimerNo") = txtduration.Text
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Private Sub submitbtn_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles submitbtn.Click
Dim i As Integer
Dim mr As RadioButton
Try
Score = 0
Answered = 0
For i = 0 To DataGrid1.Items.Count - 1
mr =
CType(DataGrid1.Items(i).FindControl("RadioButton1 "), RadioButton)
If mr.Checked Then
CheckAns(Val(mr.GroupName), mr.Text)
End If
mr =
CType(DataGrid1.Items(i).FindControl("RadioButton2 "), RadioButton)
If mr.Checked = True Then
CheckAns(Val(mr.GroupName), mr.Text)
End If
mr =
CType(DataGrid1.Items(i).FindControl("RadioButton3 "), RadioButton)
If mr.Checked = True Then
CheckAns(Val(mr.GroupName), mr.Text)
End If
mr =
CType(DataGrid1.Items(i).FindControl("RadioButton4 "), RadioButton)
If mr.Checked = True Then
CheckAns(Val(mr.GroupName), mr.Text)
End If
Next
StoreCourseScore()
Session("Comment") = "You have answered " & Answered & "
questions for " & lblCourse.Text & " . "
Response.Redirect("frmTestResult.aspx")
Catch ex As Exception
End Try
End Sub
Sub StoreCourseScore()
Try
Session("CourseScore") = Score
CalcPercentage(Score, Val(txtNoOfqns.Text))
Session("TotScore") = Session("TotScore") + Score
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub CalcPercentage(ByVal CourseScore, ByVal TotSecQns)
Try
Dim Percentage As Double
Percentage = Decimal.Round(Val(CourseScore / TotSecQns) *
100, 2)
If Percentage >= 70 Then
Session("CandStatus") = "S"
Else
Session("CandStatus") = "D"
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Sub CheckAns(ByVal qno As Integer, ByVal ans As String)
Try
Dim CorrectAns As String
Dim ds2 As New DataSet()
Dim str1, str2 As String
str2 = Session("Id")
str1 = "select f_Answer from tbl_Question where
f_questionno=" & qno & " and f_CourseId='" & str2 & "'"
ConDB.OpenConnection()
ds2 = ConDB.ExecuteSPReturnDS("ELS_ExecuteQuery", str1)
ConDB.CloseConnection()
CorrectAns = ds2.Tables(0).Rows(0)(0)
'Response.Write(",CorrectAns:" & CorrectAns & ",Ans:" &
ans)
If CorrectAns = ans Then
Score += 1
'Response.Write("Score:" & Score)
End If
Answered += 1
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DataGrid1.SelectedIndexChanged
End Sub
End Class
--
sneha123
------------------------------------------------------------------------
sneha123's Profile:
http://www.highdots.com/forums/m1273
View this thread:
http://www.highdots.com/forums/t3060098