Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 8120 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Creating multiple Header Rows in GridView ...
Mouli

Creating multiple Header Rows in GridView

 Code Snippet posted by: Mouli | Posted on: 9/18/2009 | Category: ASP.NET Codes | Views: 7974 | Status: [Member] | Alert Moderator   


We had a requirement ones to have multiple header rows. Obvious choice was to use Repeater but we could not define the Columns for the Repeater at the design time. We would know the columns and names only at the design time. AutoGenerateColumns was not available in the repeater. So I had to use GridView.
GridView does not support giving multiple header rows as we do in Repeaters using <tr> tag.

We achieved this by adding new TableRow (html row) at the runtime to the GridView Default table.

In the OnRowCreated event of the GridView,

if (e.Row.RowType == DataControlRowType.Header)

{
GridViewRow row = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal);
Table t = (Table)gv.Controls[0];

// Adding Cells
TableCell FileDate = new TableHeaderCell();
FileDate.ColumnSpan = 1;
row.Cells.Add(FileDate);

TableCell cell = new TableHeaderCell();
cell.ColumnSpan = 2; // ********
cell.Text = "Sample Text";
row.Cells.Add(cell);

t.Rows.AddAt(0, row);
}


Its also possible to have column spans in the different header rows.
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 8:36:33 AM