Counting the number of days from gridview ASP.NEt C#
So I have a gridview with records and dates. I want to count the number of days from Dateborrowed to Datereturned and display them in a label. I also want to add a fine like number of days x $1. In the meantime I'm currently following this. Just started in programming in ASP.开发者_开发技巧NET.
Any help would be much appreciated!! Thanks in advance.
You can create a TemplateField
like this with a lable
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# GetDays(Eval("Dateborrowed "), Eval("Datereturned ")) %>'></asp:Label>
</ItemTemplate>
and have a code-behind function
public string GetDays(object dateborrowed, object datereturned)
{
if(dateborrowed !=null && datereturned!=null)
{
return ((DateTime)datereturned) - ((DateTime)dateborrowed).Days.ToString() + " Days"
}
}
You can add another TemplateField for displaying fine.
精彩评论