我如何在Repeater ASP.NET中添加倒计时 [英] How I add countdown in Repeater ASP.NET

查看:51
本文介绍了我如何在Repeater ASP.NET中添加倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个数据项,我将数据源设置为转发器这些项目,

这个项目包括完成时间,



我想在转发器中像倒计时器(定时器)一样我该怎么办?

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?

推荐答案

我找到了一个答案你可以使用的问题,



I found an answer for this problem you can use,

<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>





和CodeBehind你使用这个块





and CodeBehind you use this block

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 + " ";

           }

       }


这篇关于我如何在Repeater ASP.NET中添加倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆