如题,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();
    }
}

解决方案 »

  1.   

       <select size="4" name="ListBox1" id="ListBox1">
        <option>aaaa</option>
    </select>
    <script>
    function addlist()
    {
    document.getElementById("ListBox1").options.add(new Option("text","value")); 
    }
    setInterval(addlist,2000);//2000=2秒
      

  2.   

    function addlist()
    {
    document.getElementById("ListBox1").options.add(new Option("text","value"));  
    }
    setInterval(addlist,2000);//2000=2秒  正解
      

  3.   

    很好很强大,但是,如果value值来自页面中的一个变量,又该怎么写啊
    算了,我还是吧需求都写出来吧,就是一个短信收发系统,每3秒钟查询一次是否收到短信,如果收到就显示在listbox里,该怎么实现
      

  4.   

    正解,当然用jQuery会更简单一些
      

  5.   

    楼主可以写一个系统服务或者使用Timer控件,至于如何实现Google下,很多
      

  6.   

    如果需要后台处理后再搞,就要用ajax了