radio buttons-web application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayush patel
    New Member
    • Jul 2008
    • 63

    radio buttons-web application

    Hi this is rather a simple question but i dont know why it is creating a problem. i have two radio buttons in a panel and they have to be mutually exclusive. in windows application i know it works well. but here even though i have both the buttons in panel they are not mutually exclusive. i am able to clcik on both of then.

    can any one give me a quick response for this.

    Ayush.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Use a RadioButtonList instead of individual RadioButtons.

    Comment

    • ayush patel
      New Member
      • Jul 2008
      • 63

      #3
      thanks for the reply.but this will be horizontal right. i want radio buttons to be vertically aligned.

      Comment

      • myth0s
        New Member
        • Jan 2008
        • 32

        #4
        Originally posted by ayush patel
        thanks for the reply.but this will be horizontal right. i want radio buttons to be vertically aligned.
        You can use the GroupName attribute to specify a group of buttons that should be mutually exclusive.

        Example :
        Code:
        <asp:RadioButton ID="btn1" runat="server" Text="Red" ValidationGroup="type" GroupName="color" Checked="True" />
        <asp:RadioButton ID="btn2" runat="server" Text="Blue" ValidationGroup="type" GroupName="color" />
        <asp:RadioButton ID="btn3" runat="server" Text="Green" ValidationGroup="type" GroupName="color" />
        MSDN info here : http://msdn.microsoft. com/en-us/library/system.web.ui.w ebcontrols.radi obutton.groupna me.aspx

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          Originally posted by ayush patel
          thanks for the reply.but this will be horizontal right. i want radio buttons to be vertically aligned.
          Actually, RadioButtonList defaults to vertical. However, if you don't like that, do this:
          Code:
          <asp:RadioButtonList id="rbl1" runat="server" RepeatDirection="Horizontal" ></asp:RadioButtonList>
          You can choose between Horizontal and Vertical alignment.

          There is also a RepeatColumns attribute that you can define how many columns of RadioButtons there will be.

          Edit: Groupname will work, but I always find the list to be much cleaner. The only reason I use GroupName is when I don't want the radio buttons to be near each other.

          Comment

          • ayush patel
            New Member
            • Jul 2008
            • 63

            #6
            Thanks for your quick replies.both the above tricks worked.

            Ayush

            Comment

            Working...