conditional page break inside the repeater on a dynamically created web user control

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'>&nbsp;</p>";
    }
    else
    {
     return "";
    }
   }
   catch(Exception)
   {
    return "";
   }
  }

Print | posted on Friday, September 25, 2009 12:27 PM

Feedback

No comments posted yet.

Your comment:





 

Copyright © Kevin Shyr

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski