Business Scenario:
The client wants to build a few reports (only in HTML format) that basically have the same format, but needs paging when the report is sent to the printer.
Solution:
I built the report inside a user control to reuse the formatting, but had to solve the problem where hard-coding the page break at the UI side will give me an extra page in printing. Code:
Inside ASCX:
<%# InsertPageBreakIfNotLastPage(DataBinder.Eval(Container, "ItemIndex")) %>
Code behind (C #):
public string InsertPageBreakIfNotLastPage(object o)
{
try
{
if(System.Convert.ToInt32(o) != (dsInd.Tables[0].Rows.Count - 1))
{
return "<p style='page-break-after: always'> </p>";
}
else
{
return "";
}
}
catch(Exception)
{
return "";
}
}