2012-04-22 125 views
1

我正在使用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) 
     { 
      //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); 
      } 
     } 

任何幫助,將不勝感激感謝

回答

3

確保您要導入的命名空間表MSDN Ref

是有

using System.Web.UI.WebControls; 

在你的文件的頂部?

0

不幸的是,教程通常會忽略他們正在使用的庫,這可能會讓人不安。但有一個簡單的辦法:谷歌有什麼你就得到一個錯誤,在這種情況下C# Table,第三結果下來說:

表類(System.Web.UI.WebControls) - MSDN - 微軟

並在括號之間是你需要包括庫:

@using System.Web.UI.WebControls; // for .cshtml pages 
using System.Web.UI.WebControls; // for .cs pages 

就總是包括C#中搜索,尋找一個「MSDN」的搜索結果。