Html – ‘Collapsing’ ‘RepeatColumns’ property of ASP CheckBoxList

asp.nethtml

I use the RepeatColumns of an ASP CheckBoxList to create three columns in a list of genres. This usually works OK but occasionally when the page loads the columns collapse. This seems to happen randomly and across all browsers. I do use OutputCache.

Has anyone noticed this behavior before?

This is a snippet of the code:

<table width="100%"><tr><td width="66%" style="padding-left:4px">Genres:</br>

    <asp:CheckBoxList RepeatColumns="3" CssClass="chkChoice" ID="CheckBoxList_Genres" runat="server">
        <asp:ListItem Selected="True">Action</asp:ListItem>
        <asp:ListItem Selected="True">Comedy</asp:ListItem>
        <asp:ListItem Selected="True">Classics</asp:ListItem>
        <asp:ListItem Selected="True">Documentary</asp:ListItem>
        <asp:ListItem Selected="True">Drama</asp:ListItem>
        <asp:ListItem Selected="True">Fantasy</asp:ListItem>
        <asp:ListItem Selected="True">Foreign</asp:ListItem>
        <asp:ListItem Selected="True">Independent</asp:ListItem>
        <asp:ListItem Selected="True">Kids</asp:ListItem>
    </asp:CheckBoxList>
</td>

In response to the comment, this is the rendered html:

    <span id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres" class="chkChoice"><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_0" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$0" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_0">Action</label><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_3" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$3" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_3">Documentary</label><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_6" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$6" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_6">Foreign</label><br /><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_1" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$1" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_1">Comedy</label><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_4" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$4" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_4">Drama</label><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_7" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$7" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_7">Independent</label><br /><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_2" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$2" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_2">Classics</label><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_5" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$5" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_5">Fantasy</label><input id="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_8" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList_Genres$8" checked="checked" /><label for="ctl00_ContentPlaceHolder1_CheckBoxList_Genres_8">Kids</label></span>

Best Answer

If you do not mind tabulating the checkboxlist, add RepeatLayout="Table".

E.g.

<asp:CheckBoxList RepeatColumns="3" CssClass="chkChoice" 
  ID="CheckBoxList_Genres" runat="server" 
  RepeatLayout="Table" >....
Related Topic