开发者

bind datagrid to collection

开发者 https://www.devze.com 2022-12-17 18:58 出处:网络
how do I bind a DataGrid to a collection ? (e.g : List ). i used this : Datagrid dg = new Datagrid(); dg.DataSource = myCollection;

how do I bind a DataGrid to a collection ? (e.g : List ).

i used this :

Datagrid dg = new Datagrid();
dg.DataSource = myCollection;
dg.DataBind();

but after this, the Datagrid still doesn't display the开发者_运维问答 data from the collection.


The same way as you bind a datagrid to a DataTable/DataSet. Your object properties will behave like column names when databinding.

DataGrid1.DataSource = myList;
DataGrid1.DataBind();


List<string> lst= new List<string>();

lst.Add("your string");

Datagrid dg = new Datagrid();
dg.DataSource=lst;
dg.DataBind();

disclaimer: I have not run this code, but this should give your a general idea


You have to add your Datagrid object (dg) to your form.

this.Controls.Add(dg);


Just set YourDataGrid.Datasource to the instance name of the List and call the YourDataGrid.DataBind() function.

0

精彩评论

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