Thanks klabranche, but the table just generates 10 rows and I've not been able to get my head round inserting the data into the rows.
Here is the dynamic grid method that is been called in the page load method. Thanks once again
private void loadDynamicGrid() { #region Code for preparing the DataTable
//Create an instance of DataTable
DataTable dt = new DataTable();
//Create an ID column for adding to the Datatable
//DataColumn dcol = new DataColumn(RoomCost ,typeof(System.Int32));
//dt.Columns.Add(dcol);
DataColumn dcol = new DataColumn(RoomType, typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn(Location, typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn(Restaurant, typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn(Smoking, typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn(NoOfGuests, typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn(Hotel, typeof(System.String));
dt.Columns.Add(dcol);
//dcol = new DataColumn(AvailableDate, typeof(System.DateTime));
//dt.Columns.Add(dcol);
//Now add data for dynamic columns
//As the first column is auto-increment, we do not have to add any thing.
//Let's add some data to the second column.
for (int nIndex = 0; nIndex < 10; nIndex++)
{
//Create a new row
DataRow drow = dt.NewRow();
//Initialize the row data.
//drow[RoomCost] = "Row-" + Convert.ToString((nIndex + 1));
//Add the row to the datatable.
//dt.Rows.Add(drow);
drow[RoomType] = "" + Convert.ToString((nIndex + 1));
//dt.Rows.Add(drow);
drow[Location] = "" + Convert.ToString((nIndex + 1));
//dt.Rows.Add(drow);
drow[Restaurant] = "RESTAURANT" + Convert.ToString((nIndex + 1));
//dt.Rows.Add(drow);
drow[Smoking] = "SMOKING" + Convert.ToString((nIndex + 1));
//dt.Rows.Add(drow);
drow[NoOfGuests] = "NO_OF_PEOPLE" + Convert.ToString((nIndex + 1));
//dt.Rows.Add(drow);
//drow[AvailableDate] = "Row-" + Convert.ToDateTime((nIndex + 1));
dt.Rows.Add(drow);
}
#endregion
//Iterate through the columns of the datatable to set the data bound field dynamically.
foreach (DataColumn col in dt.Columns)
{
//Declare the bound field and allocate memory for the bound field.
BoundField bfield = new BoundField();
//Initalize the DataField value.
bfield.DataField = col.ColumnName;
//Initialize the HeaderText field value.
bfield.HeaderText = col.ColumnName;
//Add the newly created bound field to the GridView.
GridView1.Columns.Add(bfield);
}
//Initialize the DataSource
GridView1.DataSource = dt;
//Bind the datatable with the GridView.
GridView1.DataBind();
}