Can I merge a footer in a GridView?

I have a GridView associated with a dataset. I have a footer that is separated by column lines. I want to combine 2 columns; how to do it?

<asp:TemplateField HeaderText="Name" SortExpression="Name"> <ItemTemplate> ... </ItemTemplate> <FooterTemplate > Grand Total: </div> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Age" SortExpression="Age"> <ItemTemplate> ... </ItemTemplate> <FooterTemplate > <%# GetTotal() %> </div> </FooterTemplate> </asp:TemplateField> 
+4
source share
3 answers

unverified code

1st lower pattern should include <% # GetTotal ()%>

The second footer template must be blank

  Protected Sub Page_SaveStateComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SaveStateComplete Dim DG As GridView = GridView1 Dim Tbl As Table = DG.Controls(0) Dim tr As GridViewRow Dim i As Integer Dim j As Integer tr = Tbl.Rows(Tbl.Rows.Count - 1) 'this line assume last row is footer row tr.Cells(0).ColumnSpan = 2 'if you have 3 columns then colspan = 3 instead For j = 1 To 1 'if you have 3 columns then j = 1 To 2 instead tr.Cells(j).Visible = False Next End Sub 
+2
source
 protected void GridView1_OnRowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells.RemoveAt(1); e.Row.Cells[0].ColumnSpan = 2; } } 
+6
source

I was doing something like this - trying to have a button, in the footer a few cols.

I ran into a problem when I set the columns through the code, because a) I am noob, and b) it was not doing what I expected. I don’t remember all the details, but there was some sort of checkmark, like adding extra columns or something else.

Here is my solution. Maybe some of them will be useful. I did a prerender for gridview (gvDocs).

And what made it work correctly for me was to programmatically delete the footer cells, and also set the columns.

Even if the code doesn’t help, maybe people will laugh at the fact that oblivious me is fascinating. Sometimes it makes me laugh.

  Protected Sub gvDocs_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvDocs.PreRender If gvDocs.Rows.Count > 0 Then Dim m As Integer = gvDocs.FooterRow.Cells.Count For i As Integer = m - 1 To 1 Step -1 If i <> 8 Then '7 is the number of the column with the applychanges button in it. gvDocs.FooterRow.Cells.RemoveAt(i) End If Next i gvDocs.FooterRow.Cells(1).ColumnSpan = 6 '6 is the number of visible columns to span. End If End Sub 

Fernando68 - Here it is in C #

 protected void gvDocs_PreRender(object sender, System.EventArgs e) { if (gvDocs.Rows.Count > 0) { int m = gvDocs.FooterRow.Cells.Count; for (int i = m - 1; i >= 1; i += -1) { //7 is the number of the column with the applychanges button in it. if (i != 8) { gvDocs.FooterRow.Cells.RemoveAt(i); } } gvDocs.FooterRow.Cells[1].ColumnSpan = 6; //6 is the number of visible columns to span. } } //======================================================= //Service provided by Telerik (www.telerik.com) //Conversion powered by NRefactory. //Twitter: @telerik //Facebook: facebook.com/telerik //======================================================= 

EDITED - use square brackets to access the cell by index in the footer row

+1
source

All Articles