Eranga Perera
Eranga Perera

Reputation: 938

How generate datagrid from code at runtime?

I need to generate a datagrid at run time from C# code.

My intention is generate datagrid from C# code and bind data to that grid at run time.

Guys can you help me to achieve this?

Upvotes: 0

Views: 217

Answers (2)

Shahid Iqbal
Shahid Iqbal

Reputation: 2135

try this..

 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);

Upvotes: 2

Sai Avinash
Sai Avinash

Reputation: 4753

DataGrid dgDetails = new DataGrid();

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

dgDetails.DataBind();

Upvotes: 0

Related Questions