2014-03-25 41 views
0

我需要從C#代碼運行時生成一個數據網格。如何在運行時從代碼生成datagrid?

我的意圖是從C#代碼生成datagrid,並在運行時將數據綁定到該網格。

夥計們你能幫我實現嗎?

+0

IS是ASP或WPF的DataGrid? – Gun

+0

c#windows窗體datagrid。 –

+0

@ErangaLakmalPerera ..查看下面的答案.. –

回答

0
DataGrid dgDetails = new DataGrid(); 

dgDetails.DataSource=dt (some data from your DB) 

dgDetails.DataBind(); 
2

試試這個..

DataGridView dgv = new DataGridView(); 
/// if your want to fill DataGridView from Database then pass your required datasource to DataGridView, like below.. 
// dgv.DataSource = dt(Some data Source); 
// if you want to add column in Code, then follow below Code.. 
dgv.Columns.Add("Column", "Name"); 
dgv.Columns.Add("Column", "Address"); 
dgv.Rows.Add("abc","xyz"); 
this.Controls.Add(dgv); 
相關問題