[Message Deleted]
-
Drag and drop a GridView and name it as GridView1 Try the below code for merging the header protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable("Employee"); //Name Age Gender Mobile Phone Email dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Columns.Add("Gender"); dt.Columns.Add("Mobile"); dt.Columns.Add("Phone"); dt.Columns.Add("Email"); dt.Rows.Add("Anoop", "25", "Male", "996633352", "02255566", "anoopukrish@gmail.com"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { GridView gridView = (GridView)sender; GridViewRow gridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert); TableCell tableCell = new TableCell(); //add Personal Info tableCell.Text = "Personal Info"; tableCell.Attributes.Add("style", "text-align: center"); tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); //Add Contact Info tableCell = new TableCell(); tableCell.Attributes.Add("style", "text-align: center"); tableCell.Text = "Contact Info"; tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); GridView1.Controls[0].Controls.AddAt(0, gridViewRow); } } ... There by u get the desired output...
-
Drag and drop a GridView and name it as GridView1 Try the below code for merging the header protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable("Employee"); //Name Age Gender Mobile Phone Email dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Columns.Add("Gender"); dt.Columns.Add("Mobile"); dt.Columns.Add("Phone"); dt.Columns.Add("Email"); dt.Rows.Add("Anoop", "25", "Male", "996633352", "02255566", "anoopukrish@gmail.com"); GridView1.DataSource = dt; GridView1.DataBind(); } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { GridView gridView = (GridView)sender; GridViewRow gridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert); TableCell tableCell = new TableCell(); //add Personal Info tableCell.Text = "Personal Info"; tableCell.Attributes.Add("style", "text-align: center"); tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); //Add Contact Info tableCell = new TableCell(); tableCell.Attributes.Add("style", "text-align: center"); tableCell.Text = "Contact Info"; tableCell.ColumnSpan = 3; gridViewRow.Cells.Add(tableCell); GridView1.Controls[0].Controls.AddAt(0, gridViewRow); } } ... There by u get the desired output...
Just a note: The original question was how to merge a *DataGridView* Control. The answer above appears to show how to merge a *GridView* Control. The two controls are not the same.