0

I need to create datagrid at runtime in and add it to one new tab.

C# 3.0 -- .net 3.5

Any starting point?

3 Answers 3

1

It's really easy...

DataGridView dg = new DataGridView();

// set columns (auto or manual)

// set appearance (lots of style options)

// set data source (IEnumerable object)
dg.DataBind();

placeHolder1.COntrols.Add(dg); // add to placeholder
Sign up to request clarification or add additional context in comments.

Comments

1

The best way to learn how to do this is to add data grid on design time and take a look on the auto generated code.

Comments

0

You can do this much the same as creating any control at runtime.

DataGridView dg = new DataGridView();
dg.ID = "grid";
....Other properties

this.tab.Controls.Add(dg);

Just remember when dynamically creating controls they must be re-created on each postback

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.