0

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?

2
  • IS it ASP or WPF datagrid? Commented Mar 25, 2014 at 5:14
  • c# windows form datagrid. Commented Mar 25, 2014 at 5:16

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0
DataGrid dgDetails = new DataGrid();

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

dgDetails.DataBind();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.