-1

I want to show Merge header of grid view using C#+ASP.net as shown in my image bellow:

enter image description here

Any idea how to achieve this?

Suresh
  • 158
  • 3
  • 16
  • [Have you tried to do some search](https://www.google.com/search?q=asp.net+gridview+merge+cells+&oq=asp.net+gridview+merge+cells+&aqs=chrome..69i57.8378j0&sourceid=chrome&ie=UTF-8)? – alex.b Sep 18 '13 at 04:33
  • 1
    Here is same question [http://stackoverflow.com/questions/5073771/gridview-merge-column-headers/9333714][1] [1]: http://stackoverflow.com/questions/5073771/gridview-merge-column-headers/9333714 – user2156093 Sep 18 '13 at 04:36
  • 1
    Take a look into these articles: http://www.codeproject.com/Articles/16049/Merge-Header-GridView-DataGrid and http://www.etechpulse.com/2013/07/c-merging-gridview-header-columnscells.html – Saritha.S.R Sep 18 '13 at 04:45
  • Hi,aleksey.berezan yes I have but not able to create gridview header as I want. – Suresh Sep 18 '13 at 04:49
  • hi,user2156093 your solution works for me. – Suresh Sep 18 '13 at 09:35

1 Answers1

2

You can use the Row_Created event of grid view. In which you can set ColSpan and Row Span property of a Grid view

See the below sample code:

protected void grvMergeHeader_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        GridView HeaderGrid = (GridView)sender;
        GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
        TableCell HeaderCell = new TableCell();
        HeaderCell.Text = "Employee Information";
        HeaderCell.ColumnSpan = 3;
        HeaderGridRow.Cells.Add(HeaderCell);

        HeaderCell = new TableCell();
        HeaderCell.Text = "Joining Date";
        HeaderCell.ColumnSpan = 2;
        HeaderGridRow.Cells.Add(HeaderCell);

        grvMergeHeader.Controls[0].Controls.AddAt(0, HeaderGridRow);

    }
}

For more reference see the below linkmerging grid view header here