[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


CheckBoxList like RadioButtonList

Posted on 2005-05-04
Medium Priority
Last Modified: 2012-06-27
I want to use a checkbox list and make it function like a radiobutton list (ie - make only one selection possible) instead of multiple selections.

Would like to have the look and feel of a checkbox list with a radiobuttonlist functionality.

Any thoughts.

Question by:steve_mick972
  • 2

Assisted Solution

dharmesh_amity earned 200 total points
ID: 13927128
Nope you can't do that directly. You will have to write javascript to do this, when you check check a box you will have to find if there is any other checkbox checked, if so uncheck it.

Accepted Solution

mcgants earned 800 total points
ID: 13927287
you can do it directly, just with a bit of coding behind the scenes - try this on:
first, put this function into your code:

  Private Function CheckBoxes(ByVal Box As CheckBox) As Boolean
    CheckBoxes = False
    Dim myControl As Control
    Dim myForm As HtmlForm
    Dim myCheckBox As CheckBox
    Dim selectedBox As String
    Dim Form1 As String = "Form1"
    myForm = CType(Page.FindControl(Form1), HtmlForm)
    For Each myControl In myForm.Controls
      If myControl.GetType.ToString = "System.Web.UI.WebControls.CheckBox" Then
        myCheckBox = CType(myControl, CheckBox)
        If myCheckBox.Checked = True And myCheckBox.ID <> Box.ID Then
          myCheckBox.Checked = False
        End If
      End If
  End Function

Next, create your textboxes, set the AutoPostBack attribute to "True" and on the CheckedChanged event handler, add the following code:

 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
      CheckBox1.Checked = True
    End If
End Sub

Replacing all the 'CheckBox1's with the name of your checkbox.
Works for me :)


Expert Comment

ID: 13927331
oh, by the way, that code will cycle through all controls on the screen, so if you want to have other check boxes that aren't in your 'Check Box List', then amend the function line:

...  If myCheckBox.Checked = True And myCheckBox.ID <> Box.ID Then ...

to include other 'ids' that you don't want to include. e.g.

...  If myCheckBox.Checked = True And myCheckBox.ID <> Box.ID And myCheckBox.ID <> chkBlah.ID Then ...


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question