Referred URL
https://sites.google.com/site/learning6329/asp-net/gridview
Merge Merging GridView Header Columns Multiple Headers ASP.NET
In this example i m explaining how to Merging Or Merge GridView Header Columns Or Combine Multiple Headers using C# In ASP.NET 2.0,3.5,4.0. For this you need to create GridView header row in RowCreated Event
<asp:GridView ID="grvMergeHeader" runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
OnRowCreated="grvMergeHeader_RowCreated">
<Columns>
<asp:BoundField DataField="DepartMentID" HeaderText="DepartMentID"/>
<asp:BoundField DataField="DepartMent" HeaderText="DepartMent"/>
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:BoundField DataField="Location" HeaderText="Location"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [DepartMentID], [DepartMent], [Name],
[Location] FROM [Employee]">
</asp:SqlDataSource>
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 =
"Department"
;
HeaderCell.ColumnSpan = 2;
HeaderGridRow.Cells.Add(HeaderCell);
HeaderCell =
new
TableCell();
HeaderCell.Text =
"Employee"
;
HeaderCell.ColumnSpan = 2;
HeaderGridRow.Cells.Add(HeaderCell);
grvMergeHeader.Controls[0].Controls.AddAt(0, HeaderGridRow);
}
}
0 comments