如题,web页面只有一个listbox,我想每隔一秒向listbox中添加一项,任意一项就可以,该怎么实现啊,我的代码如下,无法实现:public partial class _Default : System.Web.UI.Page
{
public static System.Timers.Timer gtimer = new System.Timers.Timer(1000);
public static int gcount = 0;
protected void Page_Load(object sender, EventArgs e)
{
// 创建一个计时器,单位:毫秒
gtimer = new System.Timers.Timer(3000);
// 将自定义用户函数(TimerEventFunction)指定为计时器的 Elapsed 事件处理程序
// TimerEventFunction 可以写入自己的需要执行的代码逻辑
gtimer.Elapsed += new System.Timers.ElapsedEventHandler(this.Add);
// AutoReset 属性为 true 时,每隔指定时间间隔触发一次事件
// 若赋值 false,则只执行一次
gtimer.AutoReset = true;
gtimer.Enabled = true;
}
protected void Add(object sender, EventArgs e)
{
gcount += 1;
this.ListBox1.Items.Add(new ListItem(gcount.ToString(), "tong"));
this.Label1.Text = gcount.ToString();
}
}
{
public static System.Timers.Timer gtimer = new System.Timers.Timer(1000);
public static int gcount = 0;
protected void Page_Load(object sender, EventArgs e)
{
// 创建一个计时器,单位:毫秒
gtimer = new System.Timers.Timer(3000);
// 将自定义用户函数(TimerEventFunction)指定为计时器的 Elapsed 事件处理程序
// TimerEventFunction 可以写入自己的需要执行的代码逻辑
gtimer.Elapsed += new System.Timers.ElapsedEventHandler(this.Add);
// AutoReset 属性为 true 时,每隔指定时间间隔触发一次事件
// 若赋值 false,则只执行一次
gtimer.AutoReset = true;
gtimer.Enabled = true;
}
protected void Add(object sender, EventArgs e)
{
gcount += 1;
this.ListBox1.Items.Add(new ListItem(gcount.ToString(), "tong"));
this.Label1.Text = gcount.ToString();
}
}
<option>aaaa</option>
</select>
<script>
function addlist()
{
document.getElementById("ListBox1").options.add(new Option("text","value"));
}
setInterval(addlist,2000);//2000=2秒
{
document.getElementById("ListBox1").options.add(new Option("text","value"));
}
setInterval(addlist,2000);//2000=2秒 正解
算了,我还是吧需求都写出来吧,就是一个短信收发系统,每3秒钟查询一次是否收到短信,如果收到就显示在listbox里,该怎么实现