.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to merge or group the columns in gridview....??

Posted By: Shanthini     Posted Date: July 03, 2009    Points:2   Category :ASP.Net
How to merge or group the columns in gridview....
like,

H1|H2|H3
--------
76

Provide me the ASP .NET C# codes for grouping of columns...

Responses
Author: Amit Mehra             
Posted Date: July 04, 2009     Points: 5   

Hi,
To merge column header in a gridview you can use OnRowCreated Event of Grid View.

You can Create a custom table and insert it to Row Header inside GridView

for example in c#

if (e.Row.RowType == DataControlRowType.Header)
{
//Build own custom header.
GridView oGridView = (GridView)sender;
GridViewRow oGridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell oTableCell = new TableCell();

//Add Department
oTableCell.Text = "Department";
oTableCell.ColumnSpan = 2;
oGridViewRow.Cells.Add(oTableCell);

//Add Employee
oTableCell = new TableCell();
oTableCell.Text = "Employee";
oTableCell.ColumnSpan = 3;
oGridViewRow.Cells.Add(oTableCell);
oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);
}



Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: suman             
Posted Date: July 21, 2011     Points: 20   

Thank You very much.....Can we export the grid in the same format to excel....



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend