6

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Just convert first ItemTemplate into HeaderTemplate (typing mistake?) – mshsayem Feb 20 '12 at 13:15
  • I had already tried to use HeaderTemplate instead but it's not working neither, i don't understand why ... –  Feb 20 '12 at 13:18
  • Change that to HeaderTemplate and have a look at the error panel of the browser (Ctrl+Shift+J for Firefox)... – mshsayem Feb 20 '12 at 13:25

2 Answers2

10

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.

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • Thanks but anyway this is not a serious problem is the table is built vertically. How come it's not working ? –  Feb 20 '12 at 13:39
1

It is not possible to use multiple instances of the ItemTemplate tag. You can only use one of each tag that is available with the Repeater controls.

https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.repeater.itemtemplate?view=netframework-4.8

reactionzz
  • 11
  • 1