hi
check out the following links
link1[
^]
or
try this code
private void loadDynamicGrid()
{
#region Code for preparing the DataTable
DataTable dt = new DataTable();
DataColumn dcol = new DataColumn(ID ,typeof(System.Int32));
dcol.AutoIncrement = true;
dt.Columns.Add(dcol);
dcol = new DataColumn(NAME, typeof(System.String));
dt.Columns.Add(dcol);
for (int nIndex = 0; nIndex < 10; nIndex++)
{
DataRow drow = dt.NewRow();
drow[NAME] = "Row-" + Convert.ToString((nIndex + 1));
dt.Rows.Add(drow);
}
#endregion
foreach (DataColumn col in dt.Columns)
{
BoundField bfield = new BoundField();
bfield.DataField = col.ColumnName;
bfield.HeaderText = col.ColumnName;
GrdDynamic.Columns.Add(bfield);
}
GrdDynamic.DataSource = dt;
GrdDynamic.DataBind();
}