开发者

Counting the number of days from gridview ASP.NEt C#

开发者 https://www.devze.com 2023-03-03 16:03 出处:网络
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 th

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消