473,388 Members | 873 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,388 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 2887
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.