2012-08-01 65 views
0

我有一個table與列totalnames。該表有10行。c#中的動態數據庫行表

現在我想爲我的網頁中的複選框動態地創建這10行的表。請發送一些很好的例子。

+0

你應該先試用一下你的自我,SO只有當你在某個時候卡住時纔會幫助你。記住上帝幫助那些幫助他們自我的人。 – yogi 2012-08-01 07:29:20

回答

0

示例代碼:動態創建表,添加cloumn,添加行

(1) create a new DataTable  
    DataTable dt = new DataTable ("Table_AX");  

(2) Add columns to the DataTable  
    // Method 1  
    dt.Columns.Add ("column0", System.Type.GetType ("System.String"));  
    // Method 2  
    DataColumn dc = new DataColumn ("column1", System.Type.GetType ("System.Boolean"));  
    dt.Columns.Add (dc);  

(3) to add rows to the DataTable  
    // Initialize the row  
    DataRow dr = dt.NewRow();  
    dr ["column0"] = "AX";  
    dr ["column1"] = true;  
    dt.Rows.Add (dr);  
    // Doesn't initialize the row  
    DataRow dr1 = dt.NewRow();  
    dt.Rows.Add (dr1);  

如果你想複製數據表中包括的數據儘量

DataTable dtNew = dt.Copy();