开发者

how to create datagrid at run time through code?

I need to create datagrid at runtime in and add 开发者_Python百科it to one new tab.

C# 3.0 -- .net 3.5

Any starting point?


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜