Processing Multiple Check Boxes in SQL Query

Discussion in 'ASP .Net' started by Jim in Arizona, Jul 21, 2005.

  1. 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
    Jim in Arizona, Jul 21, 2005
    #1
    1. Advertising

  2. 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).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
    >
    >
    >
    >
    >
    =?Utf-8?B?SmFjZWsgU3Rhd2lja2k=?=, Jul 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kris
    Replies:
    0
    Views:
    507
  2. kris
    Replies:
    0
    Views:
    472
  3. kris
    Replies:
    1
    Views:
    5,192
  4. Venu9955
    Replies:
    1
    Views:
    77
    Julian Leviston
    Apr 1, 2008
  5. Suresh
    Replies:
    2
    Views:
    396
    Suresh
    Apr 22, 2004
Loading...

Share This Page