I am using a grid to display no of leads. In that I have to display Page wise total as well as Grand total. Is it possible to show it in 2 different rows in Footer? Give me some suggestions. I have to add 8 columns in grid.
2 Answers
you can do this lots of ways, but one of them is to use TemplateField
here is format for your gridview (put your content in the 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> ...
You will have to create a custom GridView class by inheriting 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' page directive to refer to your custom 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> You can then set the 'PageTotal' and 'GrandTotal' properties.
GridView1.PageTotal = "5"; GridView1.GrandTotal = "10";