473,663 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
DataValueField) .
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.

http://www.wjer.net/images/problems/...list021304.gif

Dim strConn as string =
ConfigurationSe ttings.AppSetti ngs("ConnString ")

Sub Page_Load(sende r AS Object,E as EventArgs)
If Not IsPostBack Then
Dim conPubs As SqlConnection
Dim cmdSelect As SqlCommand
Dim dtrSubjects As SqlDataReader
conPubs = New SqlConnection(s trConn)
cmdSelect = New SqlCommand( "Select * From
tutors_subjectc odes order by Subject", conPubs )
conPubs.Open()
dtrSubjects = cmdSelect.Execu teReader()

check1.DataSour ce = dtrSubjects
check1.DataText Field = "Subject"
check1.DataValu eField = "subjectcod e"
check1.DataBind ()

dtrSubjects.Clo se()
conPubs.Close()
End If
End Sub

Sub btnStep2_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s)
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 &
")</li><br>"
End If
Next
lblSubjects.Tex t =
"<br><b>Selecte d:<br></b><ul>"
& msg & "</ul>"
End Sub
<asp:checkboxli st id="check1"
runat="server"
RepeatColumns=" 4"></asp:checkboxlis t>
<br>
<asp:Button id="btnStep2"
onclick="btnSte p2_Click" runat="server"
Text="Submit"></asp:Button>
<br>
<asp:label id="lblSubjects "
runat="server"> </asp:label>
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 18 '05 #1
0 1495

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

Similar topics

0
1048
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
0
1496
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 SQL DDL like follows: create table interest ( intId int, intName varchar(20)) go Insert into interest values ( 1, 'Music') Insert into interest values ( 2, 'Jogging') Insert into interest values ( 3, 'Fishing')
0
2527
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 value="My Value". Therefore, I can't access "My Value" with Request.Form on post back. I do get the desired outcome with my RadioButtonList object radioList when I do
3
5522
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 that the custom attribute can be accessed using javascript? Cheers
1
1483
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 later unselect them the last one u unselect remains printed out on the screen. How can i reset Checkboxlists back to NULL. I need to do this becos i'm passing the values to a QueryString and if the unselect and remains in the queryString its a...
3
1087
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)
2
5521
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 each checkbox that is checked, and this value will change dynamically via javascript when a box is ticked or unticked. e.g. <script language="javascript"> function GetCost() {
2
2764
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 checkBoxList. I have tried: chList as checkboxlist = findControl("ChkList") Null exception error...it doesnt exist
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.