【问题标题】:ASP.NET Repeater DataItemsASP.NET 中继器数据项
【发布时间】:2013-07-19 02:15:04
【问题描述】:

我有一个简单的中继器控件,它有 5 列和显示良好的数据。但是,我需要将第 6 个数据项放在每个表格行之后的下一行中。

我已经尝试将第 6 个项目放置在交替模板项目中,它可以执行我想要的操作,但是不会遍历所有行。

从下面的代码中,Notes 数据项是我希望在每一行之后出现在新行中的数据项...下面的代码执行此操作,但它不会循环:

        <HeaderTemplate>
             <table class="tblMoves"  >
                <tr>
                    <th>
                        Type
                    </th>
                    <th>
                        ID
                    </th>
                    <th>
                        First Name
                    </th>
                    <th>
                        Last Name
                    </th>
                    <th>
                       Date
                    </th>
                </tr>

        </HeaderTemplate>
       <AlternatingItemTemplate>
         <tr>
         <td colspan="5">   <%#Eval("Notes")%></td>
         </tr>
         </AlternatingItemTemplate>
       <ItemTemplate>

        <tr>
        <td><asp:Label ID="empid" Text='<%#Eval("type") %>' runat="server"></asp:Label></td>
                    <td><asp:Label ID="Label1" Text='<%#Eval("ID") %>' runat="server"></asp:Label></td>

        <td><asp:Label ID="Label2" Text='<%#Eval("FirstName") %>' runat="server"></asp:Label></td>

        <td><asp:Label ID="Label3" Text='<%#Eval("LastName") %>' runat="server"></asp:Label></td>
        <td><asp:Label ID="Label4" Text='<%#Eval("Date", "{0:MM/dd/yyyy}") %>' runat="server"></asp:Label></td>
        </tr>
       </ItemTemplate>



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

【问题讨论】:

    标签: repeater


    【解决方案1】:

    只需将您的备注行添加到您的项目模板。

    <ItemTemplate>
      <tr>
        <td>
          <asp:Label ID="empid" Text='<%#Eval("type") %>' runat="server"></asp:Label>
        </td>
        <td>
          <asp:Label ID="Label1" Text='<%#Eval("ID") %>' runat="server"></asp:Label>
        </td>
        <td>
          <asp:Label ID="Label2" Text='<%#Eval("FirstName") %>' runat="server"></asp:Label>
        </td>
        <td>
          <asp:Label ID="Label3" Text='<%#Eval("LastName") %>' runat="server"></asp:Label>
        </td>
        <td>
          <asp:Label ID="Label4" Text='<%#Eval("Date", "{0:MM/dd/yyyy}") %>' runat="server"></asp:Label>
        </td>
      </tr>
      <tr>
        <td colspan="5"><%#Eval("Notes")%></td>
      </tr>
    </ItemTemplate>
    

    【讨论】:

    • 谢谢CM!完美运行。
    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 2016-08-06
    相关资源
    最近更新 更多