473,289 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

selecting multiple items in a checkbox from a datagrid urgent plssssssssssssssssss


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

Nov 19 '05 #1
1 2878
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
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
0
by: Erik | last post by:
I'm trying to create a asp.net webform with a datagrid which has been filled with data from a database. The datagrid is filled allright but I would like to add a checkbox at every row which the use...
5
by: Dave | last post by:
Hi all, Apologies if this is the wrong group. I have done a search on google but my keywords are probably no good. What I want to do is to display a list of data in a datagrid (which I have...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
0
by: Patrick.O.Ige | last post by:
I have a datagrid with checkboxes.. When a user clicks one check box and clicks the delete button it deletes that ROw. There another situation when a user clicks multiple rows so i had to loop...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
4
by: sydney.luu | last post by:
Hello, I would greatly appreciate if someone can show me how to dynamically build a Repeater with unknown number of columns at design time. I have looked various threads in this newsgroup,...
1
by: kw_uh97 | last post by:
Hello everyone I have a web form that postback a datagrid that shows the most recent (pending)requests submitted to the database. On this grid I would like the user to have the ability to chose...
1
by: Priya | last post by:
I have to display a checboxlist with someitems when each item in a listbox is selected. I have a listbox with a list of categories and when i click each category from the listbox, the checkbox list...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.