簡體   English   中英

在ASP.net中使用中繼器的有序列表

[英]Ordered list using repeater in ASP.net

下面的代碼不斷給我一個錯誤:

.ASPX文件中的中繼器代碼

<asp:Repeater ID="rptDescription" runat="server">
        <HeaderTemplate><ol class="DescriptionRepeater"></HeaderTemplate>
        <ItemTemplate>
            <li>
                <a href="#"><%= this %></a>
            </li>
        </ItemTemplate>
        <FooterTemplate><ol/></FooterTemplate>
    </asp:Repeater>

在.ASPX.CS文件中填充中繼器的代碼

即時消息使用Visual Studio 2017,代碼導致有序列表填充.aspx文件的路徑

List<string> lstDescription = new List<string>();
        lstDescription.Add("this is the first description");
        lstDescription.Add("this is the second description");
        rptDescription.DataSource = lstDescription;
        rptDescription.DataBind();

這不是實際情況。 無論如何,您只需要使用Container.DataItem ,因為DataItem本身是一個字符串。 請確保使用綁定語法<%# %>而不是<%= %>

<asp:Repeater ID="rptDescription" runat="server">
    <HeaderTemplate>
        <ol class="DescriptionRepeater">
    </HeaderTemplate>
    <ItemTemplate>
        <li>
            <a href="#"><%# Container.DataItem %></a>
        </li>
    </ItemTemplate>
    <FooterTemplate>
        <ol />
    </FooterTemplate>
</asp:Repeater

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM