Last post Mar 02, 2010 01:22 AM by slj
Feb 28, 2010 05:52 AM|slj|LINK
I have a GridView with column headers that include text and images. I would like to have the header essentially duplicated at the bottom of the GridView. Does anyone have any suggestions on how to accomplish this? I have found some internet resources
that have explained how to use the GridView PreRender event to add an extra footer row but I'm trying to find a simple way to populate that row with the same text and images that appear in the header row. I am not using header templates. I am using the footer
row of the GridView as the "insert" row.
Feb 28, 2010 07:50 AM|TajKhan|LINK
Feb 28, 2010 09:26 PM|slj|LINK
Thank you for the suggestions. I had seen both of those articles but they don't really provide a solution for my problem. I don't think I explained what I'm trying to do very clearly. The 1st article you referenced explains how to create a fixed header
and footer, but it doesn't explain a way to make the footer row a copy of the header row. In my situation the content of some header columns is dynamically created in the GridView's RowCreated event. I'm trying to then use the GridView's PreRender event
to create a 2nd footer row matching the content of the header row. I'm creating the 2nd footer row using the concepts described in this article -
http://blogs.msdn.com/paraga/archive/2005/12/13/503081.aspx. I am already using the standard footer as the "insert" row as described in the 2nd article you referenced. So my real question
is this: "From the PreRender event, what is the best way to make a copy of the header row and add it as the 2nd footer row?"
GridVeiw "2nd Footer" "Duplicate Header"
Feb 28, 2010 11:09 PM|hans_v|LINK
I would like to have the header essentially duplicated at the bottom of the GridView
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
Dim grid As GridView = TryCast(sender, GridView)
If grid IsNot Nothing Then
Dim row As New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)
Dim header As GridViewRow = GridView1.HeaderRow
For i As Integer = 0 To GridView1.Columns.Count - 1
Dim TableCell As New TableHeaderCell()
TableCell.Text = header.Cells(i).Text
Dim t As Table = TryCast(grid.Controls(0), Table)
If t IsNot Nothing Then
That copies a standard header with text only, all you need to do is gind a way how to copy the images from the HeaderCell also...
Mar 01, 2010 02:48 AM|slj|LINK
Thank you for the help, I think you're helping me gt closer to a solution. The code you supplied does add a new row at the bottom of the GridView and the style matches the header style but each cell in the row is empty. Although my actual column headers
are not empty, the Text property in line 08 is empty ("") for each column.
Mar 01, 2010 03:57 AM|hans_v|LINK
the Text property in line 08 is empty ("") for each column.
Most likely because you're using a Header Template because of the images? If you would use just the header text, it will work. That's why I said that you should do a little work yourself
Let me help you a little bit further. Instead of the Text Property, retrieve the HTML that the HeaderTemplate is rendering,something like:
Dim sb As New StringBuilder()
Dim tw As New StringWriter(sb)
Dim hw As New HtmlTextWriter(tw)
TableCell.Text = sb.ToString()
But I think it needs somes tweaking, because the HeaderTempleate most likely is rendering some TD or TH tags, but I think you should be able to solve it and use perhaps some Regex to remove unwanted tags
Mar 01, 2010 09:19 PM|slj|LINK
The template columns are not the problem. Before my last response, I had tested the code you supplied in the initial post on a GridView that just used BoundFileds with no template columns. The results were the same. I'm interested to know if you tested
it yourself, maybe I've got another problem. By the way, I'm using VS2008 but the project is targeted for the 2.0 .NET framework.
I think your last suggestion may put me on the right track.
Mar 01, 2010 09:48 PM|hans_v|LINK
I'm interested to know if you tested it yourself
I just tested it, it works with bound fields
maybe I've got another problem. By the way, I'm using VS2008 but the project is targeted for the 2.0 .NET framework.
me too, so I don't see why it should not work?
I also tested my suggestion of rendering the HTML of the header. And that works also, but, as expected a header is rendering extra th tags that you need to remove....
Mar 02, 2010 01:22 AM|slj|LINK
I put in the latest code you suggested and the RenderControl(hw) method generated an the error "'DataControlLinkButton' must be placed inside a form tag with runat=server". I don't understand why it works in the header but not in the new row. Anyway, that
led me to set the AllowSorting property of the GridView to False and then your code worked for me on a GridView with just bound fields. That's a step in the right direction, I'll keep working on it. It seems like there should be a simpler way to just get
the whole HTML string generated when the header is rendered and write it to the new footer row.