title: ASP.NET C# Insert Page Break when Repeater hits bottom of page
body: <p>I have an HTML table that is generated for printing purposes.  It has a Repeater that populates from a DataSet built from SQL; so the total row count is unknown.  </p>
  
  <p>The issue is when the page is printed, table rows that are supposed to be together are separated between the end of the previous page and the beginning of the next page.  I need to insert a Page-Break to keep the table rows together.  With most efforts made found from Google Searches, the table row for the "Standard" keeps getting pushed to the next page.  Other methods just create 10+ blank pages first then the table with "Standard" on the next pages.</p>
  
  <pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"&gt;
  &lt;style type="text/css"&gt;
      body {
          font-family: Arial;
          font-size: 10pt;
      }
      table {
          border-collapse: collapse;
      }
      .alignL {
          text-align: left;
      }
      .alignC {
          text-align: center;
      }
      .alignR {
          text-align: right;
      }
      .border1 {
          border-color: black;
          border-style: groove;
          border-width: 2px;
          white-space: nowrap;
      }
      .border1L {
          border-color: black;
          border-style: groove;
          border-width: 2px;
          border-right: none;
          height: 35px;
          font-size: 12pt;
      }
      .border1R {
          background-image: url(../_images/LgtGrey.png);
          border-color: black;
          border-style: groove;
          border-width: 2px;
          font-size: 12pt;
          border-left: none;
      }
      .border2 {
          border-color: black;
          border-style: groove;
          border-width: 2px;
          border-bottom: none;
          width: 60px;
      }
      .border3 {
          border-color: black;
          border-style: groove;
          border-width: 2px;
          border-top: none;
          width: 60px;
      }
      .borderBottom {
          border-bottom-color: black;
          border-bottom-style: groove;
          border-bottom-width: 2px;
      }
      .center {
          margin-right: auto;
          margin-left: auto;
          width: 11in;
      }
  &lt;/style&gt;
  &lt;style media="print" type="text/css"&gt;
      @page {
          size: landscape;
      }
      @media print {
          thead {
              display: table-header-group;
          }
      }
  &lt;/style&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt;
  &lt;div class="page"&gt;
      &lt;div class="center"&gt;
          &lt;table class="alignC" style="width: 90%"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th colspan="16" class="alignC"&gt;
                          &lt;h3 class="alignC"&gt;Technical Evaluation Worksheet&lt;/h3&gt;
                      &lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                      &lt;th colspan="2" class="border1L alignR"&gt;
                          &lt;asp:Label ID="Label1" runat="server" Text="Model: " Font-Bold="true" /&gt;&lt;/th&gt;
                      &lt;th colspan="2" class="border1R alignC"&gt;
                          &lt;asp:Label ID="lblModel" runat="server" /&gt;&lt;/th&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                      &lt;th colspan="2" class="border1L alignR"&gt;
                          &lt;asp:Label ID="Label2" runat="server" Text="Serial #: " Font-Bold="true" /&gt;&lt;/th&gt;
                      &lt;th colspan="2" class="border1R alignC"&gt;
                          &lt;asp:Label ID="lblSN" runat="server" /&gt;&lt;/th&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                      &lt;th colspan="2" class="border1L alignR"&gt;
                          &lt;asp:Label ID="Label3" runat="server" Text="Program: " Font-Bold="true" /&gt;&lt;/th&gt;
                      &lt;th colspan="2" class="border1R alignC"&gt;
                          &lt;asp:Label ID="lblProgram" runat="server" /&gt;&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  &lt;tr class="alignC"&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td colspan="4" class="border1"&gt;(FQA)&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td colspan="4" class="border1"&gt;(MTF)&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td colspan="4" class="border1"&gt;(FA)&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Record&lt;br /&gt;
                          Error&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Circle X&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Red X&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Diagonal&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Record&lt;br /&gt;
                          Error&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Circle X&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Red X&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Diagonal&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Record&lt;br /&gt;
                          Error&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Circle X&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Red X&lt;/td&gt;
                      &lt;td class="border2 alignC"&gt;Diagonal&lt;/td&gt;
                      &lt;td rowspan="3" class="border2 alignC"&gt;&lt;b&gt;Quality&lt;br /&gt;
                          Score&lt;/b&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td valign="bottom" class="border1 alignR"&gt;Deduction&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-1%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-2%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-4%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;0%&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-1%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-2%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-4%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;0%&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-1%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-2%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;-4%&lt;/td&gt;
                      &lt;td valign="bottom" class="border3 alignC"&gt;0%&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr class="alignC"&gt;
                      &lt;td class="border1 alignR"&gt;# of Incidents&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFQA1" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFQA2" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFQA3" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFQA4" runat="server" /&gt;&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblMTF1" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblMTF2" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblMTF3" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblMTF4" runat="server" /&gt;&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFA1" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFA2" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFA3" runat="server" /&gt;&lt;/td&gt;
                      &lt;td class="border1" style="background-image: url(../_images/LgtGrey.png)"&gt;
                          &lt;asp:Label ID="lblFA4" runat="server" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr class="alignC"&gt;
                      &lt;td class="border1 alignR"&gt;Total&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFQA1" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFQA2" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFQA3" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFQA4" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTMTF1" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTMTF2" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTMTF3" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTMTF4" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFA1" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFA2" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFA3" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTFA4" runat="server" Text="0%" /&gt;&lt;/td&gt;
                      &lt;td class="border1"&gt;
                          &lt;asp:Label ID="lblTotal" runat="server" Font-Bold="true" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;asp:Repeater ID="Repeater" runat="server"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;tr&gt;
                              &lt;td class="borderBottom alignR"&gt;&lt;b&gt;Auditor:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="5" class="borderBottom alignC" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblAuditor" runat="server" Text='&lt;%# Eval("Auditor") %&gt;' /&gt;&lt;/td&gt;
                              &lt;td class="borderBottom alignR"&gt;&lt;b&gt;CTR:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="5" class="borderBottom alignC" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblCTR" runat="server" Text='&lt;%# Eval("Mitigator") %&gt;' /&gt;&lt;/td&gt;
                              &lt;td class="borderBottom alignR"&gt;&lt;b&gt;Date:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="3" class="borderBottom alignC" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblDate" runat="server" Text='&lt;%# Eval("Date", "{0:dd-MMM-yy}") %&gt;' /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td class="borderBottom alignR" style="min-height: 30px"&gt;&lt;b&gt;Finding:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="15" class="borderBottom alignL" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblFinding" runat="server" Text='&lt;%# Eval("Finding") %&gt;' /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td class="borderBottom alignR"&gt;&lt;b&gt;Status:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="5" class="borderBottom alignC" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblStatus" runat="server" Text='&lt;%# Eval("FS") %&gt;' /&gt;&lt;/td&gt;
                              &lt;td class="borderBottom alignR" colspan="2"&gt;&lt;b&gt;Location:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="8" class="borderBottom alignC" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblLocation" runat="server" Text='&lt;%# Eval("Location") %&gt;' /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td class="borderBottom alignR"&gt;&lt;b&gt;Standard:&lt;/b&gt;&lt;/td&gt;
                              &lt;td colspan="15" class="borderBottom alignC" style="background-image: url(../_images/LgtGrey.png)"&gt;
                                  &lt;asp:Label ID="lblStandard" runat="server" Text='&lt;%# Eval("Standard") %&gt;' /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:Repeater&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>