见下图:
设想
我有一个带有 Id“ rpt1 ”的转发器控件,在 ItemTemplate 内部我有一个Id 为“ abc ”的跨度控件,它当前显示一个数字。我也有一个。ticker above the repeater in format dd-MM-yyyy hh:mm:ss (27-05-2013 11:24:36), made up of ASP:Timer and ASP:UpdatePanel
要求
我需要的是,每当我的计时器的第二部分达到 00 时,我想将 span 的内容从数字更改为某个图像。
代码
ASPX:
<form id="form1" runat="server">
<asp:ScriptManager ID="scr" runat="server">
</asp:ScriptManager>
<asp:Timer ID="timer" runat="server" Interval="1000" OnTick="timer_Tick">
</asp:Timer>
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Always">
<ContentTemplate>
<asp:Label runat="server" ID="lblNum"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Repeater runat="server" ID="rpt1">
<ItemTemplate>
<table>
<tr>
<td>
<span id="abc" runat="server">
<%#Eval("Number") %></span>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</form>
CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
namespace WebTest
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindList();
}
protected void timer_Tick(object sender, EventArgs e)
{
lblNum.Text = string.Format("{0:dd:MM:yyyy hh:mm:ss}",DateTime.Now);
if (DateTime.Now.Second == 30)
{
Thread t = new Thread(DisplayImages);
t.Start();
t.Suspend();
t.Join();
}
}
private void BindList()
{
var list = new List<Numbers>();
list.Add(new Numbers() { Number = 5 });
list.Add(new Numbers() { Number = 6 });
list.Add(new Numbers() { Number = 7 });
list.Add( new Numbers() { Number = 5 });
list.Add(new Numbers() { Number = 5 });
rpt1.DataSource = list;
rpt1.DataBind();
}
private void DisplayImages()
{
foreach (RepeaterItem item in rpt1.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
var checkBox = ((HtmlGenericControl)(item.FindControl("abc")));
checkBox.InnerHtml = "<img src='http://pra.aps.org/sites/pra.test.ridge.aps.org/themes/PRA/graphics/button_go.gif'/>";
}
}
}
}
public class Numbers
{
public int Number { get; set; }
}
}
早些时候,代码是在单线程上执行的。现在,我尝试将线程分开,但无济于事。我认为每次重新加载页面是主要问题。是否有可能我只能刷新计时器部分而不是整个页面。