Create a HTML table with an ASP repeater, repeating horizontally

I’m trying to build a HTML table using an ASP repeater:

<asp:Repeater ID="RepeaterVersionsForPie" runat="server">
    <ItemTemplate>
        <table id="VersionsTable" >

                <tr>
                    <th>
                    <%#Eval("nameVersion")%>
                    </th>

                </tr>

    </ItemTemplate>
    <ItemTemplate>
        <tbody>
            <tr>
                <td tag="<%#Eval("idVersion")%>">
                    <%#Eval("NumberOfCompaniesUsingThisVersion")%>
                </td>
            </tr>
        </tbody>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

This is a basic table which consists in two lines and X columns.
The second line appears without any problems while the first one is invisible.
Can anyone help to find what’s missing?
Thanks in advance.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I think the core problem is that Repeater isn’t designed to repeat horizontally.

Maybe you should try using DataList which allows to specify the RepeatingDirection.

Update

If you don’t need to repeat horizontally (like your question suggests “…two lines and X columns”) your Repeatershould look like this

<asp:Repeater ID="RepeaterVersionsForPie" runat="server">

    <HeaderTemplate>
        <table id="VersionsTable">
    </HeaderTemplate>

    <ItemTemplate>
        <tr>
            <th><%# Eval("nameVersion") %></th>
            <!-- Important: Put attributes in single quotes so they don't get
                 mixed up with your #Eval("xxx") double quotes! -->
            <td tag='<%#Eval("idVersion")%>'>
                <%# Eval("DocumentName") %>
            </td>
        </tr>
    </ItemTemplate>

    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

Note that you must not repeat the <table> in your <ItemTemplate> and to use single quotes when you need to put your Eval inside an attribute.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x