在中继器中减去评估值

发布于 2024-12-27 09:23:15 字数 661 浏览 0 评论 0原文

如何在中继器中减去 2 个日期时间? 我想减去 2 个 requestDates 并写入 waitingTime。

       <td>
        <%#Eval("requestDates")%>
        </td>
        <td>
        <%#Eval("waitingTime")%>
        </td>

         I wanna get like 1 week 4 days 18 hours 47 minutes:>

        ID         Request_Dates                     Waiting_Time
        1      18.01.2012 09:54:38          6 days 20 hours 37 mins 13 sec
        2      11.01.2012 13:17:25                 19 hours 18 mins 47 sec
       ...            ....                                 ....

如您所见,等待时间 = (id 1 request_dates) - (id 2 request_dates) 谢谢。

How can i substract 2 datetime in repeater?
I want to substract 2 requestDates and write to waitingTime.

       <td>
        <%#Eval("requestDates")%>
        </td>
        <td>
        <%#Eval("waitingTime")%>
        </td>

         I wanna get like 1 week 4 days 18 hours 47 minutes:>

        ID         Request_Dates                     Waiting_Time
        1      18.01.2012 09:54:38          6 days 20 hours 37 mins 13 sec
        2      11.01.2012 13:17:25                 19 hours 18 mins 47 sec
       ...            ....                                 ....

as you see waiting time = (id 1 request_dates) - (id 2 request_dates)
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2025-01-03 09:23:15

一个解决方案

您可以创建一个方法并在 html 代码中调用它,如下所示:

 <td>
        <%# substraction(Eval("requestDates"),Eval("waitingTime"))%>
        </td>

在 cs 中:

public function substraction(....){}

仅考虑必须在 html 和 cs 中转换变量。

另一种解决方案
我将用 Literals 替换 Eval,添加 ItemDataBound 事件,并在方法中找到控件并分配值,在这里我可以从“e.Item”对象获取值并轻松减去它。
例如:

<asp:Repeater ID="rp" runat="server" OnItemDataBound="Item_Bound">
.....
</asp:Repeater>

 void Item_Bound(Object sender, DataListItemEventArgs e)
      {

         MyObject theobject=(MyObject) e.Item.DataItem;
         if (e.Item.ItemType == ListItemType.Item || 
             e.Item.ItemType == ListItemType.AlternatingItem)
         {

            // Retrieve the Label control in the current DataListItem.
            Label ltRequest = (Label)e.Item.FindControl("ltRequest");
          ltRequest.text=theobject.requestDates;
        ....
        /**HERE I CAN DO WHATEVER***/
     }
}

ONE SOLUTION

You can create a method and call it in your html code, in this way:

 <td>
        <%# substraction(Eval("requestDates"),Eval("waitingTime"))%>
        </td>

in the cs:

public function substraction(....){}

Only take into account that you have to cast the variables in the html and cs.

ANOTHER SOLUTION
I would replace the Eval with Literals, add an ItemDataBound event and in the method I would find the controls and assign the values, here I can get the values from the "e.Item" object and substract it easily.
For example:

<asp:Repeater ID="rp" runat="server" OnItemDataBound="Item_Bound">
.....
</asp:Repeater>

 void Item_Bound(Object sender, DataListItemEventArgs e)
      {

         MyObject theobject=(MyObject) e.Item.DataItem;
         if (e.Item.ItemType == ListItemType.Item || 
             e.Item.ItemType == ListItemType.AlternatingItem)
         {

            // Retrieve the Label control in the current DataListItem.
            Label ltRequest = (Label)e.Item.FindControl("ltRequest");
          ltRequest.text=theobject.requestDates;
        ....
        /**HERE I CAN DO WHATEVER***/
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文