CheckBoxList - how to prevent labels from wraping?

Discussion in 'ASP .Net' started by MattB, Nov 11, 2004.

  1. MattB

    MattB Guest

    Hi I have a form with a CheckBoxList that gets bound at runtime. I split it
    into columns if there are a lot of items, but the formatting of those
    columns isn't what I was looking for. Specifically, I don't like how the
    labels wrap and would like to prevent them from wrapping, but I don't see a
    property that applies to this. How can I keep the labels on one line?
    Thanks!

    Matt
    MattB, Nov 11, 2004
    #1
    1. Advertising

  2. MattB

    jongalloway Guest

    I looked into a property based approach and I don't think that's
    supported.

    I'd try wrapping the text in the ListItem in a <nobr> tag. The syntax
    would be a bit different depending on how you're doing your
    databinding.

    You may set this to using the ListItem.Text property on the server
    side, or if you're doing your databinding in the ASPX you'd use
    something like
    <asp:listitem><nobr><%#databinder.eval(...)%></nobr></asp:listitem>

    As an example, here's the code you'd use if you weren't databinding:
    <asp:CheckBoxList id="checkboxlist1"
    AutoPostBack="True"
    CellPadding="5"
    CellSpacing="5"
    RepeatDirection="Vertical"
    RepeatLayout="Flow"
    TextAlign="Right"
    OnSelectedIndexChanged="Check_Clicked"
    runat="server">

    <asp:ListItem><nobr>Item 1</nobr></asp:ListItem>
    <asp:ListItem><nobr>Item 2</nobr></asp:ListItem>
    <asp:ListItem><nobr>Item 3</nobr></asp:ListItem>
    <asp:ListItem><nobr>Item 4</nobr></asp:ListItem>
    <asp:ListItem><nobr>Item 5</nobr></asp:ListItem>
    <asp:ListItem><nobr>Item 6</nobr></asp:ListItem>
    </asp:CheckBoxList>

    - Jon
    http://weblogs.asp.net/jgalloway
    jongalloway, Nov 12, 2004
    #2
    1. Advertising

  3. MattB

    MattB Guest

    Awesome! the <nobr> tags worked like a charm. Thanks!

    Matt

    jongalloway wrote:
    > I looked into a property based approach and I don't think that's
    > supported.
    >
    > I'd try wrapping the text in the ListItem in a <nobr> tag. The syntax
    > would be a bit different depending on how you're doing your
    > databinding.
    >
    > You may set this to using the ListItem.Text property on the server
    > side, or if you're doing your databinding in the ASPX you'd use
    > something like
    > <asp:listitem><nobr><%#databinder.eval(...)%></nobr></asp:listitem>
    >
    > As an example, here's the code you'd use if you weren't databinding:
    > <asp:CheckBoxList id="checkboxlist1"
    > AutoPostBack="True"
    > CellPadding="5"
    > CellSpacing="5"
    > RepeatDirection="Vertical"
    > RepeatLayout="Flow"
    > TextAlign="Right"
    > OnSelectedIndexChanged="Check_Clicked"
    > runat="server">
    >
    > <asp:ListItem><nobr>Item 1</nobr></asp:ListItem>
    > <asp:ListItem><nobr>Item 2</nobr></asp:ListItem>
    > <asp:ListItem><nobr>Item 3</nobr></asp:ListItem>
    > <asp:ListItem><nobr>Item 4</nobr></asp:ListItem>
    > <asp:ListItem><nobr>Item 5</nobr></asp:ListItem>
    > <asp:ListItem><nobr>Item 6</nobr></asp:ListItem>
    > </asp:CheckBoxList>
    >
    > - Jon
    > http://weblogs.asp.net/jgalloway
    MattB, Nov 12, 2004
    #3
    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. Replies:
    6
    Views:
    428
    Jonathan N. Little
    Apr 4, 2006
  2. Mark

    Labels within a CheckBoxList

    Mark, Apr 17, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    300
  3. Dan

    To stop text wraping in an datagrid asp.net 2003

    Dan, Feb 25, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    89
  4. student77

    Hiding CheckboxList labels

    student77, Dec 7, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    277
    student77
    Dec 7, 2005
  5. Mark

    Labels within a CheckBoxList

    Mark, Apr 16, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    118
Loading...

Share This Page