Saturday, February 5, 2011

How do you stop RadioButtonList Label text from wrapping under the button

I have a radio button list and some of the labels are quite long so they wrap and the second line appears underneath the radio button. Ideally I would like the text to wrap with the second line starting beneath the first character of the first line.

Any ideas on how? or would I have to make my own list based control for this?

  • You can take a radio button and a seperate label and set the AssociatedControlID property of that label.

    <table>
        <tr>
            <td>
                <asp:RadioButton runat="server" ID="rdo" />
            </td>
            <td>
                <asp:Label runat="server" ID="lbl" Text="Radio Text" AssociatedControlID="rdo" />
            </td>
        </tr>
    </table>
    
    Mark Dickinson : Thanks, I was hoping to not have to do even more table layout so I'm going with the style idea.
    From Kirtan
  • This CSS actually does the trick:

    <style type="text/css">
     table.radioWithProperWrap input
     {    
          float: left;
     }
    
     table.radioWithProperWrap label
     {    
          margin-left: 25px;
          display: block;
     }
    </style>
    <asp:RadioButtonList runat="server" CssClass="radioWithProperWrap" ....>
    
    Mark Dickinson : Many thanks, I had a similar style in place that worked for IE and was just sorting which element to force to display:block when you hit the nail on the head.
  • try a negative text-indent style -20px works for IE8

    From Fred

0 comments:

Post a Comment