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.
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
Just set YourDataGrid.Datasource to the instance name of the List and call
the YourDataGrid.DataBind() function.
You have to add your Datagrid object (dg) to your form.
this.Controls.Add(dg);