脚本
var biddate, InitiateDateTemp, CountDownTimerTemp;
function countdown(InitiateDate, CountDownTimer) {
InitiateDateTemp = InitiateDate;
CountDownTimerTemp = CountDownTimer;
biddate = InitiateDate.innerHTML;
var kickoff = Date.parse(biddate);
var now = Date.now();
var diff = kickoff - now;
//debugger;
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
var hours = Math.floor(diff / (1000 * 60 * 60));
var mins = Math.floor(diff / (1000 * 60));
var secs = Math.floor(diff / 1000);
var dd = days;
var hh = hours - days * 24;
var mm = mins - hours * 60;
var ss = secs - mins * 60;
if (mm < 10) {
mm = "0" + mm;
}
if (ss < 10) {
ss = "0" + ss;
}
if (dd < 0) {
CountDownTimerTemp
.innerHTML = "time up";
}
else {
CountDownTimerTemp.innerHTML =
dd + ':' +
hh + ':' +
mm + ':' +
ss;
}
}
</script>
ASP.net
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:ListView ID="Listview1" runat="server">
<ItemTemplate>
<tr style="_background-color:#DCDCDC;color: #000000;">
<td>
<asp:Label ID="field1" runat="server" Text='<%# Eval("field1") %>' />
</td>
<td>
<asp:Label ID="field2" runat="server"
Text='<%# Eval("field2") %>' />
</td>
<td>
<asp:Label ID="field3" runat="server"
Text='<%# Eval("field3") %>' />
</td>
<td>
<asp:Label ID="field4" runat="server"
Text='<%# Eval("field4") %>' />
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate >
<asp:Label ID="InitiateDate" Text='<%# Eval ("InitiateDate") %>' runat="server" ></asp:Label>
<div id="CountDownTimer" runat="server" >Timer</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick"></asp:Timer>
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server" class="ListViewLayoutTable">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1" class="ListViewLayoutTable"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr id="Tr2" runat="server" style="background-color:#DCDCDC;color: #000000;">
<th id="Th7" runat="server">
field1</th>
<th id="Th1" runat="server">
field2</th>
<th id="Th2" runat="server">
field3</th>
<th id="Th3" runat="server">
field4</th>
<th id="Th4" runat="server">
timer</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
public partial class Shops : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
DataTable dt = new DataTable();
dbServices service = new dbServices("MyConnection");
SqlCommand command = new SqlCommand("SELECT * FROM table", service.SqlCon);
SqlDataReader drRecord = command.ExecuteReader();
dt.Load(drRecord);
ShopBidsTable.DataSource = dt;
ShopBidsTable.DataBind();
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Timer time = (Timer)sender;
ListViewItem item = (ListViewItem)time.Parent.Parent;
ListView lst = (ListView)time.Parent.Parent.Parent;
foreach (ListViewItem listItem in lst.Items)
{
Label InitiateDate = item.FindControl("InitiateDate") as Label;
HtmlGenericControl CountDownTimer = item.FindControl("CountDownTimer") as HtmlGenericControl;
if (CountDownTimer.InnerHtml != "time up")
{
ScriptManager.RegisterStartupScript(InitiateDate, this.GetType(), "AKey" + item.DataItemIndex, "countdown(" + InitiateDate.ClientID + " ," + CountDownTimer.ClientID + ");", true);
}
}
}
class A
{
public string Leave_Status { get; set; }
public DateTime datetime { get; set; }
}
}
これがすべて私のコードです...