PLease just try this you will get your result using System; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack){ BindGridviewData(); }}protected void BindGridviewData(){System.Web.UI.WebControls.DataGrid DataGrid1 = new System.Web.UI.WebControls.DataGrid();DataTable dt = new DataTable();dt.Columns.Add("UserId", typeof(int));dt.Columns.Add("Name", typeof(string));dt.Columns.Add("Education", typeof(string));dt.Columns.Add("Location", typeof(string));DataRow dr = dt.NewRow();dr["UserId"] = 1;dr["Name"] = "Nisha";dr["Education"] = "High level";dr["Location"] = "Delhi";dt.Rows.Add(dr);dr = dt.NewRow();dr["UserId"] = 2;dr["Name"] = "Rahul";dr["Education"] = "Low level";dr["Location"] = "Mumbai";dt.Rows.Add(dr);DataGrid1.DataSource = dt;DataGrid1.DataBind();form1.Controls.Add(DataGrid1);} }
same like as we create dynamic control in asp.net.
create object of gridview row ,cell,header and add at run-time explicitly.