472,959 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Way to loop code for inserting Checkboxlist values into DB?

I am trying to do two things for a test app:
1) Populate a CheckboxList webcontrol by loading a list of subject
names (for the DataTextField) and subject codes (for the
2) Respond to user selection by inserting their boolean values based
on checked vs. unchecked boxes. I have a SQL Server table with a lot
of columns of data type bit. All of the columns are named after
different subject codes (such as HSmath, HSast, etc.)

The first step I can do fine - but the second I am have trouble with.
How would I write looping code that would insert the status of each
checkbox into a field with names after the checkbox's value? Meaning,
how would I get HSmath's checked status to be inserted into the
HSmath field in my table, and then the HSast's checked status to be
inserted into the HSast field, and so on.

I have included my code thus far (removing unnecessary markup),
including my looping code for printing out results on the screen
(screenshot attached) - obviously this is what I'd replace with my
database code. Any help is appreciated.


Dim strConn as string =

Sub Page_Load(sender AS Object,E as EventArgs)
If Not IsPostBack Then
Dim conPubs As SqlConnection
Dim cmdSelect As SqlCommand
Dim dtrSubjects As SqlDataReader
conPubs = New SqlConnection(strConn)
cmdSelect = New SqlCommand( "Select * From
tutors_subjectcodes order by Subject", conPubs )
dtrSubjects = cmdSelect.ExecuteReader()

check1.DataSource = dtrSubjects
check1.DataTextField = "Subject"
check1.DataValueField = "subjectcode"

End If
End Sub

Sub btnStep2_Click(ByVal sender As System.Object, ByVal e As
Dim msg As String
Dim li As ListItem
msg = ""
For Each li In check1.Items
If li.Selected = True Then
msg = msg & "<li> " & li.Text &
" (" & li.Value &
End If
lblSubjects.Text =
& msg & "</ul>"
End Sub
<asp:checkboxlist id="check1"
<asp:Button id="btnStep2"
onclick="btnStep2_Click" runat="server"
<asp:label id="lblSubjects"
Posted Via Usenet.com Premium Usenet Newsgroup Services
Nov 18 '05 #1
0 1449

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

Similar topics

by: CJ | last post by:
I need example on storing Checkboxlist values in sql database. How to Insert values in checkboxlist to DB How to update values in checkboxlist from DB How to declare table and field in DB
by: Agi Chen | last post by:
Hello, theres, I'm newbie in asp.net. I have problem in CheckBoxList binding to database. Considering my case in a member system, if I have 2 tables one for interest, one for memberInterest the...
by: Boris | last post by:
When I dynamically create CheckButtonList, I add ListItem(s) to my CheckButtonList object chkList chkList.Items.Add(new ListItem("My Text", "My Value")); The resulting HTML doesn't contain...
by: Dune | last post by:
Hi, Is there anyway to get the datavaluefield from a databound checkboxlist using javascript? If not, is there any way to associate a custom attribute with the databound checkboxlist items so...
by: Patrick.O.Ige | last post by:
I have CheckboxList Databinded below and that works fine and i can get the selected values after PostBack. But what i have noticed is that when you select a checkbox i.e lets say 3 of them and...
by: Stephen | last post by:
Hi, I have a question on checkboxlist, suppose I have a checkboxlist and has listitems like USA Canada UK Germany Australia Suppose I have a resultset that has values (USA, UK and Australia)
by: Stimp | last post by:
I have a checkboxlist (chkMyList) which is created from a (name, value) pair from a database table. I have a read-only textbox which will be used to hold a total of all the numerical values of...
by: RSH | last post by:
Hi, I have a CheckBoxList that is dynamically created in the codebehind. When I click the submit button on the form I am handling the click event but I cant get at the checked values of the...
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.