简体   繁体   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>

this repeater filled in c# as 此中继器用c#填充为

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

"ApplicationSteps"property contains many elements,which contains another property called submitactiontypeid as this image shows: “ ApplicationSteps”属性包含许多元素,该元素包含另一个名为submitactiontypeid属性,如下图所示:

在此处输入图片说明

I want to get the value of submitactiontypeid which exist in the last elment of ApplicationSteps 我想获取存在于ApplicationSteps的最后一个submitactiontypeid中的submitactiontypeid的值

I asked what I shall write in <%# Eval("ApplicationSteps") %> 我问我将在<%# Eval("ApplicationSteps") %>写什么

I came with a different solution for you. 我为您提供了另一种解决方案。

If you are not available to modify your code behind, still we don't need the repeater to solve. 如果您不能修改后面的代码,我们仍然不需要中继器来解决。

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

<%=item.ApplicationSteps %>

<%}%>

This is your basic Repeater. 这是您的基本中继器。 Because of I do not know what your data type that you bind to the repater, I use dynamic type. 由于我不知道您绑定到报告程序的数据类型是什么,所以我使用动态类型。

You can modify for your purpose. 您可以根据自己的目的进行修改。

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

First, debug without adding this line. 首先,调试时不添加此行。 If it works fine, add the code above and try again. 如果正常,请添加上面的代码,然后重试。

If you just need to render that value in the page then the repeater is useless. 如果只需要在页面中呈现该值,则repeater是无用的。 Try this code: 试试这个代码:

ASP 均价

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

Then Server side (C#) 然后是服务器端(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;
    }
}

The repeater is useful when you need to render some html for each value inside an array of objects. 当您需要为对象数组中的每个值呈现一些html时, repeater很有用。 In this case you are clearly not doing that. 在这种情况下,您显然没有这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM