Subscribe to Subscribers

Forums » .NET » ASP.NET »

Display the time time left


Posted Date: 12 Jul 2012      Posted By:: Sindhu     Member Level: Bronze    Member Rank: 0     Points: 5   Responses: 3



I have a formview in which i am displaying the number of people who bought a product, the time left to buy the product etc. I am stuck up on how to display the time time left to buy the product. I have the date of expiry in db. I want to subtract that date from current date time to get the time left to buy the product. How do i do it? I am loading everything like number of people who bought etc dynamically from db onto the page using Eval. Is there a similar functionality to display the time left?
Pl help me.
Thanks in advance.




Responses

#679973    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 17     Date: 12/Jul/2012   Rating: 2 out of 52 out of 5     Points: 2

Hi,

Try below code snippet:


int expire_day = expire_date.Day;// expire_date is the date fetched from database
DateTime today = DateTime.Now;
int now = today.Day;
lblMessage.Text = (expire_day - now).ToString() + " remains!!!";


Hope it'll help you.
Regards
Ajatshatru


 
#679975    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 12/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

You can try the Ajax Timer control for the same. Here is the sample code.


<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:Timer runat="server" id="Timer1" interval="5000" ontick="Timer1_Tick" />
<asp:UpdatePanel runat="server" id="TimePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="Label1" />
</ContentTemplate>
</asp:UpdatePanel>
</form>



AND


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
}


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM


 
#679985    Author: Sindhu      Member Level: Bronze      Member Rank: 0     Date: 12/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

I want to show the time left inside of a formview. So how to get that done. I mean i want to implement it in the .aspx only. Cant it be done like that? whats the possibility? Is it possible to pass database value into jquery?




 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Reporting Services in ASP.NET
Previous : How to load data without postBack?
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.