How to add 2 rows to the Gridview footer

I use the grid to display the number of leads. In this I should display the total number of pages as well as the total number. Is it possible to show it in two different lines in the footer? Give me some tips. I have to add 8 columns to the grid.

+4
source share
2 answers

you can do this in many ways, but one of them is to use TemplateField

here is the format for your gridview (put your content in cells) ...

<Columns> <asp:TemplateField> <FooterTemplate> <table width="100%"> <tr><td><asp:Literal runat="server" ID="ltField1" Text='<%# Bind("field1") %>'></asp:Literal></td> </tr> <tr><td>><asp:Literal runat="server" ID="ltField2" Text='<%# Bind("field2") %>'></asp:Literal></td> </tr> </table> </FooterTemplate> 

...

+4
source

You will need to create your own GridView class, inheriting it from the GridView type.

 namespace CustomControls { public class CustomGridView : GridView { private string _pageTotal; public string PageTotal { get { return _pageTotal; } set { _pageTotal = value; } } private string _grandTotal; public string GrandTotal { get { return _grandTotal; } set { _grandTotal = value; } } public CustomGridView() { } protected override void OnRowCreated(GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Footer) { e.Row.SetRenderMethodDelegate(CreateFooter); } base.OnRowCreated(e); } private void CreateFooter(HtmlTextWriter PageOutput, Control FooterContainer) { StringBuilder footer = new StringBuilder(); footer.Append("<td>" + this._pageTotal +"</td>"); footer.Append("</tr>"); footer.Append("<tr>"); footer.Append("<td>" + this._grandTotal + "</td>"); footer.Append("</tr>"); PageOutput.Write(footer.ToString()); } } } 

Then use the 'Register' directive to reference your user control.

 <%@ Register TagPrefix="cc" Namespace="CustomControls" %> 

Add your control to the page, make sure ShowFooter is set to true.

 <cc:CustomGridView ID="GridView1" ShowFooter="true"></cc:CustomGridView> 

Then you can set the PageTotal and GrandTotal properties.

 GridView1.PageTotal = "5"; GridView1.GrandTotal = "10"; 
+2
source

All Articles