创建动态表 [英] Creating a dynamic table

查看:105
本文介绍了创建动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#来开发我的技能。我正在尝试一个在线发现的教程: http://geekswithblogs.net/dotNETvinz/archive/2009/03/17/dynamically-adding-textbox-control-to-aspnet-table.aspx ,但是当我尝试代码并添加生成表方法,它告诉我, Table table = new Table(); 的类型或命名空间名称无法找到..有没有人知道什么命名空间我应该用于此。这是代码的其余部分:

  private void GenerateTable(int colsCount,int rowsCount)
{
//创建表并将其添加到页面
Table table = new Table();
table.ID =Table1;
Page.Form.Controls.Add(table);
//现在遍历表并添加您的控件
(int i = 0; i< rowsCount; i ++)
{
TableRow row = new TableRow();
for(int j = 0; j< colsCount; j ++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();

//为每个TextBox添加唯一的ID
tb.ID =TextBoxRow_+ i +Col_+ j;

//将控件添加到TableCell
cell.Controls.Add(tb);
//将TableCell添加到TableRow
row.Cells.Add(cell);
}
//将TableRow添加到表
table.Rows.Add(row);
}
}

任何帮助将非常感谢谢谢

解决方案

确保您正在导入表 MSDN参考



是否有一个

 使用System.Web.UI.WebControls; 

在您的文件顶部?


I'm working with C# to develop my skills. I am trying a tutorial that I have found online: http://geekswithblogs.net/dotNETvinz/archive/2009/03/17/dynamically-adding-textbox-control-to-aspnet-table.aspx but when I try the code and add the Generate table method it tells me that the type or the namespace name for Table table = new Table(); could not be found.. does anyone know what namespace I should use for this. This is the rest of the code:

  private void GenerateTable(int colsCount, int rowsCount)
        {
            //Creat the Table and Add it to the Page
            Table table = new Table();
            table.ID = "Table1";
            Page.Form.Controls.Add(table);
            // Now iterate through the table and add your controls 
            for (int i = 0; i < rowsCount; i++)
            {
                TableRow row = new TableRow();
                for (int j = 0; j < colsCount; j++)
                {
                    TableCell cell = new TableCell();
                    TextBox tb = new TextBox();

                    // Set a unique ID for each TextBox added
                    tb.ID = "TextBoxRow_" + i + "Col_" + j;

                    // Add the control to the TableCell
                    cell.Controls.Add(tb);
                    // Add the TableCell to the TableRow
                    row.Cells.Add(cell);
                }
                // Add the TableRow to the Table
                table.Rows.Add(row);
            }
        }

any help would be much appreciated thanks

解决方案

Make sure that you are importing the namespace for table MSDN Ref

is there a

using System.Web.UI.WebControls;

at the top of your file?

这篇关于创建动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆