Skip to content Skip to sidebar Skip to footer

Can I Merge Footer In Gridview?

I have a GridView that is bound with a dataset. I have my footer, whichis separated by the column lines. I want to merge 2 columns; how do I do that?

Solution 1:

protectedvoidGridView1_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;

        }

    }

Solution 2:

untested code

1st footer template should include <%# GetTotal() %>

2nd footer template should be empty

ProtectedSub Page_SaveStateComplete(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.SaveStateComplete
        Dim DG As GridView = GridView1
            Dim Tbl As Table = DG.Controls(0)
            Dim tr As GridViewRow
            Dim i AsIntegerDim j AsInteger

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 insteadFor j = 1To1'if you have 3 columns then j = 1 To 2 instead
                        tr.Cells(j).Visible = FalseNextEndSub

Solution 3:

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

I ran into a problem when I set columnspan via code, because a) I'm a noob, and b) it was not doing what I expected. I don't remember all the details, but there was some kind of gotcha in there - like it was adding extra columns or something.

Here was my solution. Maybe some of it will be useful. I did in the prerender for the gridview (gvDocs).

And what got it working correctly for me, was programatically removing cells of the footer as well as setting the columnspan.

Even if the code doesn't help, maybe people will get a laugh at the encroaching forgetfulness afflicting me. It makes me laugh sometimes.

ProtectedSub gvDocs_PreRender(ByVal sender AsObject, ByVal e As System.EventArgs) Handles gvDocs.PreRender

        If gvDocs.Rows.Count > 0ThenDim m AsInteger = gvDocs.FooterRow.Cells.Count
            For i AsInteger = m - 1To1Step -1If i <> 8Then'7 is the number of the column with the applychanges button in it.
                    gvDocs.FooterRow.Cells.RemoveAt(i)
                EndIfNext i
            gvDocs.FooterRow.Cells(1).ColumnSpan = 6'6 is the number of visible columns to span.EndIfEndSub

Fernando68 - Here it is in C#

protectedvoidgvDocs_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 - Needed to use square brackets to access cell by index in the footer row

Post a Comment for "Can I Merge Footer In Gridview?"