团购代码,时间倒计时功能

这个是页面部分
<asp:Repeater ID="repGroupList" runat="server" OnItemDataBound="repGroupList_ItemDataBound">
                                    <ItemTemplate>
                                        <div class="group_box_list">
                                            <dl οnmοuseοver="this.className='tg_hover'" οnmοuseοut="this.className='tg_link'">
                                                <dt><a href="GroupShopDetatil.aspx?ShopID=<%#Eval("id") %>" class="txt_site">【<%#Eval("ShopName") %>】</a><a href="GroupShopDetatil.aspx?ShopID=<%#Eval("id") %>" class="txt_a"><%#Eval("ShopIntro") %></a>
                                                </dt>
                                                <dd class="image">
                                                    <a href="GroupShopDetatil.aspx?ShopID=<%#Eval("id") %>">
                                                        <img src='UploadFile/GroupShop/<%#Eval("ShopImg") %>' width="264" height="157" /></a>
                                                    <span class="new_icon">
                                                        <img src="images/xin.gif" width="44" height="44" /></span>
                                                            <asp:Label ID="lbEndTime" runat="server" Text='<%#Eval("ShopEndTime") %>' style="display:none;"></asp:Label>
                                                </dd>
                                                <dd class="like">
                                                    <span>商家点评:</span><img src="images/l07.gif" width="15" height="15" /><img src="images/h09.gif"
                                                        width="15" height="15" /></dd>
                                                <dd class="goods_info">
                                                    <span class="value">原价:<del><asp:Label ID="lbYuanPrice" runat="server" Text='<%#Eval("ShopPrice")%>'></asp:Label></del></span>
                                                    <span class="rebate">折扣<em><asp:Label ID="lbZhekou" Text='<%#Eval("ShopRebate")%>'
                                                        runat="server"></asp:Label></em>折</span> <span class="bought"><em>20</em>人购买</span>
                                                </dd>
                                                <div class="clear">
                                                </div>
                                                <dd class="go_buy">
                                                    <span class="price">¥<asp:Label ID="lbprice" Text="" runat="server"></asp:Label></span>
                                                    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                                        <ContentTemplate>
                                                            <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                                                            </asp:Timer>
                                                        </ContentTemplate>
                                                    </asp:UpdatePanel> 
                                                    <span class="downtime"><asp:UpdatePanel ID="UpdatePanel1" runat="server">
          <ContentTemplate><asp:Label ID="lblday" Text="1234564" runat="server" ></asp:Label> </ContentTemplate>
        </asp:UpdatePanel></span><a href="GroupShopDetatil.aspx?ShopID=<%#Eval("id") %>" class="buy">
                                                        <img src="images/buy.gif" width="66" height="30" /></a>
                                                </dd>
                                            </dl>
                                        </div>
                                    </ItemTemplate>
 </asp:Repeater>
这个是后台代码
 
/// <summary>
    /// 绑定的时候判断
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void repGroupList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Label lblday = (Label)e.Item.FindControl("lblday");
            Label lbyuanjia = (Label)e.Item.FindControl("lbYuanPrice");//原价
            Label lbzhihou = (Label)e.Item.FindControl("lbZhekou");//折扣
            Label lbprice = (Label)e.Item.FindControl("lbprice");//现在价格
            Label lbEndTime = (Label)e.Item.FindControl("lbEndTime");//获取结束日期

            TimeSpan CountdownSpan = new TimeSpan();
            try
            {
                CountdownSpan = DateTime.Parse(lbEndTime.Text) - DateTime.Now;
            }
            catch
            { }
            string secoud = CountdownSpan.TotalSeconds.ToString().Substring(0, CountdownSpan.TotalSeconds.ToString().IndexOf('.'));
            if (int.Parse(secoud) <= 0)
            { lblday.Text = "已过期"; }
            else
            {
                lblday.Text = CountdownSpan.Days.ToString() + "天"
                   + CountdownSpan.Hours.ToString() + "小时"
                   + CountdownSpan.Minutes.ToString() + "分钟"
                   + CountdownSpan.Seconds.ToString() + "秒";

            }
            double price = (double.Parse(lbyuanjia.Text) * double.Parse(lbzhihou.Text)) / 100;
            lbprice.Text = price.ToString();
        }
    }
    /// <summary>
    /// 执行Time的事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in repGroupList.Items)
        {
            Label lblday = (Label)item.FindControl("lblday");
            if (lblday.Text == "已过期")
            { }
            else
            {
                TimeSpan CountdownSpan = new TimeSpan();
                Label lbEndTime = (Label)item.FindControl("lbEndTime");
                TimeSpan TimeEnd = new TimeSpan(DateTime.Parse(lbEndTime.Text).Ticks);//获取结束日期
                TimeSpan NowTime = new TimeSpan(DateTime.Now.Ticks);
                try
                {
                    CountdownSpan = NowTime.Subtract(TimeEnd).Duration();
                }
                catch
                { }
                string secoud = CountdownSpan.TotalSeconds.ToString().Substring(0, CountdownSpan.TotalSeconds.ToString().IndexOf('.'));
                if (int.Parse(secoud) <= 0)
                { lblday.Text = "已过期"; }
                else
                {
                    lblday.Text = CountdownSpan.Days.ToString() + "天"
                    + CountdownSpan.Hours.ToString() + "小时"
                    + CountdownSpan.Minutes.ToString() + "分钟"
                    + CountdownSpan.Seconds.ToString() + "秒";
                }
            }
        }
    }
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值