|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis is a How It WorksThis control inherits from the regular void ReportGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
{
_currentPageRow++;
if (_currentPageRow == this._printPageSize)
{
_currentPageRow = 0;
e.Row.SetRenderMethodDelegate(PageBreakRender);
}
}
}
Now, the last row of each page will use our protected void PageBreakRender(HtmlTextWriter output, Control container)
{
HtmlTextWriter cellsWriter = new HtmlTextWriter(new StringWriter());
foreach (Control c in container.Controls)
{
TableCell cell = (TableCell)c;
cell.RenderControl(cellsWriter);
}
output.Write("<tr>");
output.Write(cellsWriter.InnerWriter.ToString());
output.Write("</tr></table>");
output.Write(GetPageFooterHtml());
//If it is the last row, don't show the next header
if (_currentPrintPage == PrintPageCount && Rows.Count %
(_currentPrintPage) == 0)
return;
output.Write("<div style=\"page-break-after:always;\"></div>");
output.Write(GetHeaderHtml());
_currentPrintPage++;
}
Note that there is a call to a method named This is the main idea behind the control. I also added the capability to render a custom page header and page footer defined in templates. Enabling the use of templates is very straight forward and you should find plenty of resources about it on the internet. You can also take a closer look at the source code to see how it works. How To Use ItThis control will work just like a regular
The control's opening tag should be something like this: <wc:ReportGridView runat="server" BorderWidth="1"
ID="gvSample" PrintPageSize="23" AllowPrintPaging="true"
AutoGenerateColumns="false">
That's it. Adding these two properties will make ASP.NET output several You can still insert custom content between each Here is the <wc:ReportGridView runat="server" BorderWidth="1"
ID="gvSample" AutoGenerateColumns="false" PrintPageSize="23"
AllowPrintPaging="true"
Width="600px">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Customer Name" />
<asp:BoundField DataField="PhoneNumber"
HeaderText="Customer Phone"
ItemStyle-HorizontalAlign="center" />
</Columns>
<PageHeaderTemplate>
<br />
PAGE HEADER TEMPLATE HERE
<br />
</PageHeaderTemplate>
<PageFooterTemplate>
<br />
<hr />
Page <%# gvSample.CurrentPrintPage.ToString() %> /
<%# gvSample.PrintPageCount %>
</PageFooterTemplate>
</wc:ReportGridView>
Notice that there are a couple more properties that we can use in the templates:
It can be used to display the page number at the footer or at the header of the page, as we can see in the sample picture above. Known IssuesWhen using Firefox, the ConclusionIn this article, we saw how we can extend the
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||