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>
Now In Code behind, in RowCreated Event of grid view i m creating a new gridview row of header type and than in this row i m adding 2 cells
C# CODE
protected void grvMergeHeader_RowCreated(object sender, GridViewRowEventArgs e){ if (e.Row.RowType == DataControlRowType.Header) {Row HeaderGridRow = new GridViewRow(0, 0, DataContrGridView HeaderGrid = (GridView)sender; GridVie wolRowType.Header, DataControlRowState.Insert); TableCell HeaderCell = new TableCell();HeaderCell.Text = "Department"; HeaderCell.ColumnSpan = 2; Head e HeaderCell = new TableCell(); HeaderCell.Text = "Employee"; HeaderCell.ColumnSpan = 2;rGridRow.Cells.Add(HeaderCell);HeaderGridRow.Cells.Add(HeaderCell); grvMergeHeader.Controls[0].Controls.AddAt(0, HeaderridRow);}}G
No comments:
Post a Comment