public void load_dynamic_grid() { try { DataTable dt = new DataTable(); string name = txtnm.Text; DataColumn dcol = new DataColumn(name, typeof(System.String)); dt.Columns.Add(dcol); DataRow drow = dt.NewRow(); drow[name] = "Rows" ; dt.Rows.Add(drow); 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. gvAlumni.Columns.Add(bfield); } //Initialize the DataSource gvAlumni.DataSource = dt; //Bind the datatable with the GridView. gvAlumni.DataBind(); } catch (Exception ex) { throw (ex); } } protected void btnSave_Click(object sender, EventArgs e) { load_dynamic_grid(); txtnm.Text = ""; }
public static DataTable dt; protected void btnSave_Click(object sender, EventArgs e) { dt.Columns.Add(txtnm.Text+"\n"+"grade"+txtgrade.Text); dt.Rows.Add("ROWS"); gvAlumni.DataSource = dt; gvAlumni.DataBind(); txtnm.Text = ""; txtgrade.Text = ""; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)