将标题添加到asp.net中的转发器

时间:2018-07-17 10:17:38

标签: c# asp.net webforms repeater

如何在Repeater控件中添加标题?我想为提到的每列添加标题

下面是我的中继器控件

<asp:Repeater ID="rptSingleSapDataInfo" runat="server">                                     
    <ItemTemplate>
        <div class="widget-box widget-blue">
            <div class="widget-main widget-repeater-horizontal">                                
                <div class="pull-left">
                    <asp:Label ID="lblSapId" runat="server"  Text='<%# DataBinder.Eval(Container.DataItem, "SAP_ID") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblState" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "STATE") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblNLat" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "NEW_LATITUDE") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblNLong" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "NEW_LONGITUDE") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblOLat" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OLD_LATITUDE") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblOLong" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OLD_LONGITUDE") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right1" style="padding: 5px 5px 5px 20px;">
                    <asp:Label ID="lblRemarks" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "REMARKS") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblCreatedBy" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CREATED_BY") %>' CssClass="labelbold"></asp:Label>
                </div>

                <div class="pull-right">
                    <asp:Label ID="lblCreatedDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CREATED_DATE", "{0:dd-MM-yyyy}") %>' CssClass="labelbold"></asp:Label>
                </div>

            </div>
        </div>
    </ItemTemplate>                   
</asp:Repeater>

2 个答案:

答案 0 :(得分:1)

您已经在使用ItemTemplate,所以请使用HeaderTemplate添加标题:

<asp:Repeater ID="rptSingleSapDataInfo" runat="server">
    <HeaderTemplate>
        My header
    </HeaderTemplate>
    <ItemTemplate>
        <div class="widget-box widget-blue">
            ...
        </div>
    </ItemTemplate>
</asp:Repeater>

答案 1 :(得分:0)

据我所知,您使用标题模板

<asp:Repeater runat="server" ID="rowRepeater" OnItemDataBound="rowRepeater_ItemBound">
    <HeaderTemplate>
        <table>                                
        <tr>
            <asp:Repeater runat="server" ID="headerRepeater">
                <ItemTemplate>
                    <th>
                        <%# Container.DataItem %>
                    </th>
                </ItemTemplate>
            </asp:Repeater>
        </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td><asp:Label runat="server" ID="lblUserName" Text='<%# Eval("Key") %>' /></td>
            <asp:Repeater runat="server" ID="columnRepeater">
                <ItemTemplate>
                    <td>
                        <asp:HiddenField runat="server" ID="hfRoleIndex" Value='<%# Container.ItemIndex %>' />
                        <asp:CheckBox runat="server" ID="cbColumnValue" Checked='<%# Container.DataItem %>' OnCheckedChanged="cbColumnValue_CheckedChanged" AutoPostBack="true" />
                    </td>
                </ItemTemplate>
            </asp:Repeater>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

这是参考链接 Repeater and add columns to header and itemtemplate on page load

它将为您提供帮助