簡體   English   中英

如何獲取中繼器中屬性的最后一個元素的值

[英]How to get the value of the last element of property in repeater

     <asp:Repeater ID="ReptServices" runat="server" OnItemDataBound="ReptServices_OnItemDataBound">
                      <b>
                  <td>    <%# Eval("ApplicationSteps") %></td>
                     <td><%# Eval("Service.ServiceName") %></td>
                            <td>
                                <b><%# Eval("BeneficiaryUserUnitJob.User.NameAr") %>  </b>
                            </td>
                            <td><%# Eval("DateCreated") %></td>
                      </b>
       </asp:Repeater>

此中繼器用c#填充為

ReptServices.DataSource = new ApplicationLogic(ApplicationType.Web).GetAllOutboxApplication(_currentUserUnitJob);

“ ApplicationSteps”屬性包含許多元素,該元素包含另一個名為submitactiontypeid屬性,如下圖所示:

在此處輸入圖片說明

我想獲取存在於ApplicationSteps的最后一個submitactiontypeid中的submitactiontypeid的值

我問我將在<%# Eval("ApplicationSteps") %>寫什么

我為您提供了另一種解決方案。

如果您不能修改后面的代碼,我們仍然不需要中繼器來解決。

<%
var repeaterDataSource = (dynamic)ReptServices.DataSource;
foreach (var item in repeaterDataSource)
{%>

<%=item.ApplicationSteps %>

<%}%>

這是您的基本中繼器。 由於我不知道您綁定到報告程序的數據類型是什么,所以我使用動態類型。

您可以根據自己的目的進行修改。

<%=item.ApplicationSteps.Last().SubmitActionTypeId  %>

首先,調試時不添加此行。 如果正常,請添加上面的代碼,然后重試。

如果只需要在頁面中呈現該值,則repeater是無用的。 試試這個代碼:

均價

<asp:Label runat="server" ID="SubmitActionType"></asp:Label>

然后是服務器端(C#)

using System;
using System.Collections.Generic;
using System.Linq;

public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var applicationSteps = GetApplicationSteps(); //Call the function that gives you the data you need

        var lastElement = applicationSteps.Last(); //Get the last element

        SubmitActionType.Text = lastElement.SubmitActionTypeId;
    }
}

當您需要為對象數組中的每個值呈現一些html時, repeater很有用。 在這種情況下,您顯然沒有這樣做。

暫無
暫無

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

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