Link to home
Start Free TrialLog in
Avatar of cdemott33
cdemott33Flag for United States of America

asked on

ASP RadioButton Value?

I added group of  <asp:RadioButton> to my page, set it's text value and then went to set the value property but apparently there is no value property.  (huh???)

RadioButtonList doesn't work for me because I wish to style my 10 RadioButtons in 2 columns and 5 rows versus having them all stack up vertically.  (unless there is a way to do this that I'm not aware of)

So I'm confused.  RadioButtonList allows me to assign values but a plain old RadioButton does not.  

Help!
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A <asp:RadioButton> is nothing more than the ASP.NET representation of an <input type="radio">. It has bells and whistles hung on it, but in essense it has not value property because this is actually set by the text property (they should have named the text property "value" to be more clear).

A <asp:RadioButtonList> allows for text and value properties because it builds labels for each <input> it builds, assigning Text to the label and Value to the <input>. in short it makes sense that there is no text & value property.

To make a <asp:RadioButtonList> behave in the way you described you can set the RepeatDirection and RepeatColumns properties (Note: there is also a RepeatLayout property that will control whether it renders a <table> or using <div> tags.

So you can do this to get two columns, hope that helps:
<asp:RadioButtonList ID="rb1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2">
      <asp:ListItem Text="rb1" Value="1"></asp:ListItem>
      <asp:ListItem Text="rb2" Value="2"></asp:ListItem>
      <asp:ListItem Text="rb3" Value="3"></asp:ListItem>
      <asp:ListItem Text="rb4" Value="4"></asp:ListItem>
      <asp:ListItem Text="rb5" Value="5"></asp:ListItem>
      <asp:ListItem Text="rb6" Value="6"></asp:ListItem>
</asp:RadioButtonList>