title: Printing a Gridview - how to print n rows on each page using page break
body: <p>I have a gridview with 30 rows.I want to print it in 3 pages with 10 rows each.I have tried this code.</p>
  
  <pre><code>        foreach (GridViewRow row in GridView1.Rows)
          {
              if (row.RowIndex % 10 == 0 &amp;&amp; row.RowIndex != 0)
              {
                  row.Attributes["style"] = "page-break-after:always;";
              }
          }
  </code></pre>
  
  <p>But it prints the whole page without any page breaks.I used to call print function using javascript(shown below).</p>
  
  <p></p>
  
  <pre><code>    function PrintGridData() {
          var prtGrid = document.getElementById('&lt;%=GridView1.ClientID %&gt;');
          prtGrid.border = 0;
          //GridView1.Attributes(style) = "page-break-after:always"         
          var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
          prtwin.document.write(prtGrid.outerHTML);
          prtwin.document.close();
          prtwin.focus();
          prtwin.print();
          prtwin.close();
      }
  </code></pre>
  
  <p></p>
  
  <p>Help???</p>
  
  <p>Regards... </p>
  
  <p>I am showing my complete markup below..pls check it..</p>
  
  <pre><code>&lt;%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeBehind="About.aspx.cs" Inherits="WebApplication2.About" EnableEventValidation="false" %&gt;
  
  &lt;%@ Register assembly="Shared.WebControls" namespace="Shared.WebControls" tagprefix="cc1" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
      &lt;h2&gt;
          About
      &lt;/h2&gt;
      &lt;script type="text/javascript"&gt;
  
          function PrintGridData() {
              var prtGrid = document.getElementById('&lt;%=ReportGridView1.ClientID %&gt;');
  
                  //window.print();
              prtGrid.border = 0;
              //GridView1.Attributes(style) = "page-break-after:always"         
              var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
              prtwin.document.write(prtGrid.outerHTML);
              prtwin.document.close();
              prtwin.focus();
              prtwin.print();
              prtwin.close();
          }
  &lt;/script&gt;
     &lt;p&gt;
          &lt;asp:Button ID="Button1" runat="server" Text="Button" 
               onclick="Button1_Click" OnClientClick="PrintGridData()"/&gt;
  &amp;nbsp;&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
              BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
              CellPadding="4" DataKeyNames="ID" DataMember="DefaultView" 
              ForeColor="Black" GridLines="None" 
              ShowFooter="True" style="margin-left: 0px; margin-right: 0px; margin-top: 3px;" 
              Width="965px" 
              ShowHeaderWhenEmpty="True" 
              EnableTheming="True" onrowcreated="GridView1_RowCreated" 
              onrowdatabound="GridView1_RowDataBound"&gt;
              &lt;AlternatingRowStyle BackColor="White" BorderStyle="Solid" /&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="Select"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:CheckBox ID="chkrow" runat="server" AutoPostBack="True" 
                              TabIndex="1" ToolTip="Select" /&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;HeaderTemplate&gt;
                          &lt;asp:CheckBox ID="chkhead" runat="server" /&gt;
                      &lt;/HeaderTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:CommandField ButtonType="Button" HeaderText="Edit" ShowEditButton="True"&gt;
                  &lt;ControlStyle CssClass="classname" /&gt;
                  &lt;/asp:CommandField&gt;
                  &lt;asp:TemplateField HeaderText="First Name"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblfirstname" runat="server" Text='&lt;%# Eval("First_name") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditfirstname" runat="server" 
                              Text='&lt;%# Eval("First_name") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="Second Name"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblsecondname" runat="server" Text='&lt;%# Eval("Second_name") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditsecondname" runat="server" 
                              Text='&lt;%# Eval("Second_name") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="DOB"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lbldob" runat="server" Text='&lt;%# Eval("DOB") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditdob" runat="server" Text='&lt;%# Eval("DOB") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="Address"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lbladdress" runat="server" Text='&lt;%# Eval("Address") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditaddress" runat="server" Text='&lt;%# Eval("Address") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="PIN"&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditpin" runat="server" Text='&lt;%# Eval("PIN") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblpin" runat="server" Text='&lt;%# Eval("PIN") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="Contact No"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblcontactno" runat="server" Text='&lt;%# Eval("Contact_no") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditcontactno" runat="server" 
                              Text='&lt;%# Eval("Contact_no") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="E-mail"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblemail" runat="server" Text='&lt;%# Eval("E_mail")%&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
  
                      &lt;EditItemTemplate&gt;
                          &lt;asp:TextBox ID="txteditemail" runat="server" Text='&lt;%# Eval("E_mail") %&gt;'&gt;&lt;/asp:TextBox&gt;
                      &lt;/EditItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
              &lt;/Columns&gt;
              &lt;FooterStyle BackColor="#CCCC99" /&gt;
              &lt;HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /&gt;
              &lt;PagerSettings Visible="False" /&gt;
              &lt;PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /&gt;
              &lt;RowStyle BackColor="#F7F7DE" /&gt;
              &lt;SelectedRowStyle BackColor="#CE5D5A" CssClass="SelectedRowStyle" 
                  Font-Bold="True" ForeColor="White" /&gt;
              &lt;SortedAscendingCellStyle BackColor="#FBFBF2" BorderStyle="Double" /&gt;
              &lt;SortedAscendingHeaderStyle BackColor="#848384" /&gt;
              &lt;SortedDescendingCellStyle BackColor="#EAEAD3" /&gt;
              &lt;SortedDescendingHeaderStyle BackColor="#575357" /&gt;
          &lt;/asp:GridView&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p></p>
  
  <p>Help???</p>