locked
Header & Footer in Gridview RRS feed

  • Question

  • User-797751191 posted

    Hi

      How to display Header Text in Footer also in Gridview

    Thanks

    Wednesday, July 3, 2019 4:56 PM

All replies

  • User409696431 posted

    Set the GridView's ShowFooter attribute to true, and for each field where you have defined HeaderText, also define the same FooterText.  Simple example:

        <asp:GridView ID="GridView1" runat="server" ShowFooter="True" OnDataBound="GridView1_DataBound" DataSourceID="SqlDataSource1" >
            <Columns>
                <asp:BoundField DataField="UserName" HeaderText="User Name" FooterText="User Name" />
                <asp:BoundField DataField="Id" HeaderText="Id" FooterText="Id" />
            </Columns>
        </asp:GridView>

    Thursday, July 4, 2019 2:23 AM
  • User-1038772411 posted

    Hello, jsshivalik

    If you want to set the Header manually, you can remove the HeaderText in TemplateField, so you can set it as you want.
    
    For making changes in Header row you can handle RowDataBound event of GridView (sample for merging all cell in header row):
    
    Protected Sub gridViewData_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) 
        If e.Row.RowType = DataControlRowType.Header Then 
            e.Row.Cells(0).ColumnSpan = 5 
            e.Row.Cells(0).Text = "Amount" & "***"   'any text for header
            For i As Integer = e.Row.Cells.Count - 1 To 1 Step -1 
                e.Row.Cells.RemoveAt(i) 
            Next 
        End If 
    End Sub

    Please Refer Below link :

    https://forums.asp.net/t/1476095.aspx?GridView+Header+Footer+Row

    Thanks.

    Friday, July 12, 2019 10:10 AM