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

Top 5 Contributors of the Month
Melody Anderson

Home >> Code Snippets >> DataGrid >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Merge two GridView Header column in ASP.NET

Posted By:Faizal       Posted Date: November 19, 2008    Points: 10    Category: DataGrid    URL: http://www.dotnetspark.com  

Below code sample shows hows how to Merge or combine two GridView Header in asp.net. the code i have used is C#. With this you can merge two pr more column with minimal code changes. Lets see the code.

All we nee to write the code in ItemCreated event of the DataGrid

protected void myGridView_ItemCreated(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType == DataControlRowType.Header)
            //custom header.
            GridView gvHeader = (GridView)sender;
            GridViewRow gvHeaderRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            TableCell tc1 = new TableCell();

            // First column
            tc1.Text = "Merged Column1";
            tc1.ColumnSpan = 2;
            tc1.BackColor = System.Drawing.Color.Brown;

             // Second  column 

            tc1 = new TableCell();
            tc1.Text = "Merged Column2";
            tc1.ColumnSpan = 2;

           gvHeader.Controls[0].Controls.AddAt(0, gvHeaderRow);



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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