creating multiple datagrids during runtime
-
I wonder if it is possible to create multiple datagrids during runtime and bind these to records of data. I tried the following code but it did not work. Any help is very appreciated. foreach(....) { // for every loop the collection of objects will contain different data //and will be bound to a different datagrid control int numberOfGoals; for(int i = 0; i< numberOfGoals; i++) { DataGrid activityDatagrid = new DataGrid(); activityDatagrid.ID = i.ToString(); activityDatagrid.AutoGenerateColumns =true; activityDatagrid.DataSource = CollectionActivities;//collection of objects activityDatagrid.DataBind(); Page.Controls.Add(activityDatagrid.ID); } }
-
I wonder if it is possible to create multiple datagrids during runtime and bind these to records of data. I tried the following code but it did not work. Any help is very appreciated. foreach(....) { // for every loop the collection of objects will contain different data //and will be bound to a different datagrid control int numberOfGoals; for(int i = 0; i< numberOfGoals; i++) { DataGrid activityDatagrid = new DataGrid(); activityDatagrid.ID = i.ToString(); activityDatagrid.AutoGenerateColumns =true; activityDatagrid.DataSource = CollectionActivities;//collection of objects activityDatagrid.DataBind(); Page.Controls.Add(activityDatagrid.ID); } }
The code will work for sure but you need to map to the datasource more specifically Eg : dataset,"TableName" or dataset,tableno