473,549 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Processing Multiple Check Boxes in SQL Query

I'm having dificulty figuring out how to process multiple check boxes on a
web form.

Let's say I have three check boxes:
cbox1
cbox2
cbox3

The only way I can think of to code the possibilities is something like:

If cbox1.checked = true then
..........
End if

If cbox2.checked = true then
.......
End If

If cbox3.checked = true then
.......
End if

If cbox1.checked = true and cbox2.checked = true then
.......
end if

If cbox1.checked = true and cbox3.checked = true then
.......
end if

And the If/End IFs go on forever!

As you can see, if I have around 8 check boxes, doing it this way could lead
to tremendous amounts of coding. I'm sure there's a better, easier way,
right? I thought of using a select case but that wouldn't be much better I
don't think.

Terry in the dotnet.vb newsgroup gave this suggestion:

dim c as integer = 0
if cbox3.Checked = True then c = 1
if cbox2.Checked = True then c += 2
if cbox1.Checked = True then c+=4

Select Case c
Case 0 'No checks
Case 1 'cbox 3
Case 2 'cbox 2
Case 3 'cbox 2 & 3
Case 4 'cbox 1
Case 5 'cbox 1 & 3
Case 6 'cbox 1 & 2
Case 7 'cbox 1,2, & 3
End Select

I thought this was a great idea, but when you have 7 checkboxes, that still
leaves 128 Cases within a select case statement to program.

Is there a dynamic way to code this scenario that works with web forms?

The application is a query that runs against a single table in an access
database. Each check box represents each field they could chose from to show
up in a table or other style report.

TIA,
Jim


Nov 19 '05 #1
1 3089
Hi Jim.
Try loop thru controls array or search this controls by specifc name:

for (int i = 0; i < page.Controls.C ount; i ++)
((Checkbox)Page .FindContol("ch b" + i.ToString())). Checked
or
((Checkbox)Page .Controls[i]).Checked

Of course this is just a tip ;)

Regards from Poland.

--
C# Dev
"Jim in Arizona" wrote:
I'm having dificulty figuring out how to process multiple check boxes on a
web form.

Let's say I have three check boxes:
cbox1
cbox2
cbox3

The only way I can think of to code the possibilities is something like:

If cbox1.checked = true then
..........
End if

If cbox2.checked = true then
.......
End If

If cbox3.checked = true then
.......
End if

If cbox1.checked = true and cbox2.checked = true then
.......
end if

If cbox1.checked = true and cbox3.checked = true then
.......
end if

And the If/End IFs go on forever!

As you can see, if I have around 8 check boxes, doing it this way could lead
to tremendous amounts of coding. I'm sure there's a better, easier way,
right? I thought of using a select case but that wouldn't be much better I
don't think.

Terry in the dotnet.vb newsgroup gave this suggestion:

dim c as integer = 0
if cbox3.Checked = True then c = 1
if cbox2.Checked = True then c += 2
if cbox1.Checked = True then c+=4

Select Case c
Case 0 'No checks
Case 1 'cbox 3
Case 2 'cbox 2
Case 3 'cbox 2 & 3
Case 4 'cbox 1
Case 5 'cbox 1 & 3
Case 6 'cbox 1 & 2
Case 7 'cbox 1,2, & 3
End Select

I thought this was a great idea, but when you have 7 checkboxes, that still
leaves 128 Cases within a select case statement to program.

Is there a dynamic way to code this scenario that works with web forms?

The application is a query that runs against a single table in an access
database. Each check box represents each field they could chose from to show
up in a table or other style report.

TIA,
Jim


Nov 19 '05 #2

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

Similar topics

1
1710
by: Pax S | last post by:
I need a button that will check (make true) two check boxes (fields) For the record that has the focus (the record on the form that I am presently looking at). The two check boxes would be like a "sold" check box and an "add to report" check box (for print out). Also as part of this button, I would like for it to enter a date into a field...
2
3744
by: Craig M | last post by:
Hi, I have a form, frmInvoices and a subform, frmInvoicesSub. On the parent form, i have a "print report" button, that prints a report depending on an ID on the parent form. Each record in the subform has a check box, "invoiced". Currently, my print report button has the folowing code:
11
4505
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my database,just help in getting me pointed in the right direction. I have a database with 8 tables, which from what I have read, cannot be linked...
6
4967
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a...
10
15942
by: Jim in Arizona | last post by:
I'm having dificulty figuring out how to process multiple check boxes on a web form. Let's say I have three check boxes: cbox1 cbox2 cbox3 The only way I can think of to code the possibilities is something like:
6
9389
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report....
1
11498
by: Euge | last post by:
Hi, I really hope someone will be able to help me with this one as I am sure im just missing something simple. I have an unbound form which has 20 yes/no unbound check boxes. The purpose of the form is to allow users to tick the various fields and a subform return the results. The subform, which does requery when a check box is ticked is...
2
3021
by: hollinshead | last post by:
hi there, i have been having this issue for quite some time now and i cant seem to get my head around it. I am trying to create a database for candidates CV's and covering letters. basically the data that is stored is made up of qualifications and areas of business that candidate is involved etc. My problem is with the query by form where i...
2
2570
by: Ru55ell | last post by:
Hi I have written a form that has 4 drop down selection boxes on it, with check boxes next to them. When a user selects something from the drop down box the check box is automatically selected. I want to perfom a query and based on what has been selected from the drop down boxes use this information as the criteria. If a user has only selected...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7957
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...
1
7470
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...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
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...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.