这个是页面部分
<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() + "秒"; } } } }