Create a gridview in the page
Drag and drop the GridView on to the page
Or
Manually type GridView definition in the page.
public partial class _Default : System.Web.UI.Page
{
#region constants
const string NAME NAME ;
const string ID ID ;
#endregion
protected void Page_Load(object sender EventArgs e)
{
loadDynamicGrid();
}
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();
}
}