Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

selecting multiple items in a checkbox from a  datagrid   urgent plssssssssssssssssss

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sneha123 - 31 Oct 2005 09:16 GMT
There will be some 20 questions and  for each question there will be  
choices.what i want to do is to select multiple answers by clicking th
checkbox. i m using asp.net,vb.net
pls help me

we have written the code using radio button for selecting singl
item.but we  want to replace it with checkbox to select multiple items
the code using radio button is given below .pls correct it wit
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 A
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 wher
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 fo
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(*)  fro
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 < NoOfQuestionsToDispla
Then
Response.Write("<Scrip
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("qnumber"), 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 = "selec
f_QuestionNo,f_Question,f_choice1,f_choice2,f_choice3,f_choice4,f_Answe
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_TimeDuration 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

Signature

sneha123

Rob Schieber - 31 Oct 2005 19:54 GMT
Are you joking?  I think you're missing the point of these groups.  If
you have a specific question, we can try to answer it, but we aren't
going to do your homework for you.

--
Rob Schieber

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.