Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a data items and I set datasource to a repeater these items,
and this items included finish time,

and I want to put like a countdown(timer) in repeater How can I do?
Posted
Comments
ZurdoDev 1-Jan-14 19:49pm    
This does not make any sense.
ammoti 2-Jan-14 11:42am    
Why :) I found answer
ZurdoDev 2-Jan-14 11:42am    
Glad to hear. Wish I could have helped. Please post as a solution so that this no longer shows under unanswered.

1 solution

I found an answer for this problem you can use,

ASP.NET
<asp:updatepanel runat="server" xmlns:asp="#unknown">
                          <contenttemplate>
                              <asp:timer id="Timer1" runat="server" interval="1000" ontick="Timer1_Tick"></asp:timer>

                              <asp:repeater runat="server" id="rptOffers" onitemdatabound="rptOffers_ItemDataBound">
                                  <itemtemplate>
                                              <asp:label id="Label3" runat="server" text="<%#Eval("DueDate") %>" visible="False">
                                              </asp:label>
                                              <asp:label id="Label1" runat="server"></asp:label>
                                              <asp:label id="Label2" runat="server" />


                                  </itemtemplate>
                              </asp:repeater>
                          </contenttemplate>
                          <triggers>
                              <asp:asyncpostbacktrigger controlid="Timer1" eventname="Tick" />
                          </triggers>
                      </asp:updatepanel>


and CodeBehind you use this block

C#
protected void Timer1_Tick(object sender, EventArgs e)
       {

           foreach (RepeaterItem item in rptOffers.Items)
           {
               var label2 = item.FindControl("Label2") as Label;

               var label3 = item.FindControl("Label3") as Label;
               var time2 = DateTime.Parse(label3.Text);
               label2.Text = (time2 - DateTime.Now).Days + " " + (time2 - DateTime.Now).Hours + " " + (time2 - DateTime.Now).Minutes + " " + (time2 - DateTime.Now).Seconds + " ";

           }

       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900