【问题标题】:What is my best option for Creating and refreshing my Placeholder?创建和刷新占位符的最佳选择是什么?
【发布时间】:2013-09-04 18:44:40
【问题描述】:

我需要使用 CreateTable 方法来创建我的表,然后我需要我的表每隔几秒刷新一次所有值,我尝试使用 System.Threading.Thread.Sleep 并使用计时器。但是,由于各种原因,例如表格未显示或循环太快,我无法使其正常工作,对此我的最佳选择是什么?对任何建议持开放态度,也是使用 PlaceHolder 来显示我的表格的最佳选择,如果不是,我应该使用什么?感谢您提前提供任何帮助。

    protected void CreateTable()
    {
        int tblColumns = 20;
        int tblRows = 50;
        //Create the table
        Table tbl = new Table();

        tbl.CssClass = "table";
        //Add table
        PlaceHolder1.Controls.Add(tbl);
        Random RandomNumber = new Random();
        for (int i = 0; i < tblRows; i++)
        {
            TableRow tr = new TableRow();
            for (int j = 0; j < tblColumns; j++)
            {
                TableCell tc = new TableCell();
                int Range = RandomNumber.Next(1, 99);
                tc.Text = Range.ToString();

                int tblCell = Convert.ToInt32(tc.Text);
                int thrsVal = Convert.ToInt32(TextBox1.Text);

                if (tblCell < thrsVal)
                {
                    tc.CssClass = "red";
                }
                else if (tblCell == thrsVal)
                {
                    tc.CssClass = "green";
                }
                else if (tblCell > thrsVal)
                {
                    tc.CssClass = "yellow";
                }
                else
                {

                }
                //Add Columns
                tr.Cells.Add(tc);
            }
            //Add Rows
            tbl.Rows.Add(tr);
        }
    }

    protected void btnGo_Click(object sender, EventArgs e)
    {
        CreateTable();
    }

【问题讨论】:

  • 什么是 PlaceHolder1?

标签: c# asp.net timer placeholder timing


【解决方案1】:

使用 ajax 更新面板和计时器控件 http://msdn.microsoft.com/en-us/library/cc295400.aspx

查看本教程

【讨论】:

  • 抱歉回复晚了,我一直在旅行,我已经将这个添加到我的代码中并且运行良好,非常感谢您的贡献!
  • 请注意,不鼓励仅链接的答案,因此答案应该是搜索解决方案的终点(相对于另一个参考中途停留,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-01
  • 1970-01-01
  • 2011-04-11
  • 2012-08-15
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
相关资源
最近更新 更多