Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Processing Multiple Check Boxes in SQL Query

Reply
Thread Tools

Processing Multiple Check Boxes in SQL Query

 
 
Jim in Arizona
Guest
Posts: n/a
 
      07-20-2005
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




 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmFjZWsgU3Rhd2lja2k=?=
Guest
Posts: n/a
 
      07-21-2005
Hi Jim.
Try loop thru controls array or search this controls by specifc name:

for (int i = 0; i < page.Controls.Count; i ++)
((Checkbox)Page.FindContol("chb" + 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
>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query regarding disable check boxes Venu9955 Ruby 1 04-01-2008 07:52 AM
Build dynamic sql query for JSTL <sql:query> Anonymous Java 0 10-13-2005 10:01 PM
how to check all check boxes in repeater control kris ASP .Net 1 09-22-2005 07:16 PM
how to check all check boxes in repeater control kris ASP .Net 0 09-22-2005 06:29 PM
how to check all check boxes in repeater control kris ASP .Net 0 09-22-2005 06:29 PM



Advertisments