如何在中继器中减去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
... .... ....
如您所见,等待时间=(Id1 request_dates) -(Id2 request_dates)谢谢。
发布于 2012-01-18 08:27:52
ONE SOLUTION
您可以创建一个方法并在html代码中调用它,方法如下:
<td>
<%# substraction(Eval("requestDates"),Eval("waitingTime"))%>
</td>
在cs中:
public function substraction(....){}
只需考虑到您必须在html和cs中强制转换变量。
对于另一个解决方案,我会用文字替换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***/
}
}
https://stackoverflow.com/questions/8907102
复制