Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在打印某些行后在DataGrid中添加分页符_C#_Asp.net_Datagrid_Page Break - Fatal编程技术网

C# 如何在打印某些行后在DataGrid中添加分页符

C# 如何在打印某些行后在DataGrid中添加分页符,c#,asp.net,datagrid,page-break,C#,Asp.net,Datagrid,Page Break,我有一个显示作业列表的DataGrid。当我打印此列表时,如果它转到另一页,则某些行会被截断。我想在15行之后加一个分页符。因此,一旦DataGrid转到第15行,它将转到下一页进行打印 <asp:DataGrid CssClass="tblResults" runat="server" ID="dgDetails" AutoGenerateColumns="false"> <HeaderStyle CssCl

我有一个显示作业列表的DataGrid。当我打印此列表时,如果它转到另一页,则某些行会被截断。我想在15行之后加一个分页符。因此,一旦DataGrid转到第15行,它将转到下一页进行打印

 <asp:DataGrid  CssClass="tblResults" runat="server" ID="dgDetails" AutoGenerateColumns="false">
                                <HeaderStyle CssClass="tblResultsHeader" />
                                <AlternatingItemStyle BackColor="#EEEEEE" />
                                <Columns>
                                    <asp:TemplateColumn HeaderText="Job">
                                        <ItemTemplate>
                                            <%# DataBinder.Eval(Container.DataItem,"JobNo") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Date">
                                        <ItemTemplate>
                                            <%# DataBinder.Eval(Container.DataItem, "DeliverDateTime")%>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="Collect From">
                                        <ItemTemplate>
                                            <%# DataBinder.Eval(Container.DataItem, "CollectionAddressInvoice")%>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn HeaderText="DeliverTo">
                                        <ItemTemplate>
                                            <%# DataBinder.Eval(Container.DataItem,"DeliveryAddressInvoice") %>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
DataSet dsTable = null;
            dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint" + q.Job.JobScreen);
            if (dsTable.Tables[0].Rows.Count == 0)
            {
                dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint");
            }
            if (dsTable.Tables[0].Rows.Count > 0)
            {
                DataGrid dgDetails = new DataGrid();
                dgDetails.ID = "dgResults";
                dgDetails.Width = new Unit(dsTable.Tables[0].Rows[0]["Width"].ToString());
                dgDetails.BorderWidth = new Unit(dsTable.Tables[0].Rows[0]["BorderWidth"].ToString());

                switch (dsTable.Tables[0].Rows[0]["GridLines"].ToString().ToUpper())
                {
                    case "BOTH":
                        dgDetails.GridLines = GridLines.Both;
                        break;
                    case "HORIZONTAL":
                        dgDetails.GridLines = GridLines.Horizontal;
                        break;
                    case "NONE":
                        dgDetails.GridLines = GridLines.None;
                        break;
                    case "VERTICAL":
                        dgDetails.GridLines = GridLines.Vertical;
                        break;
                }
                dgDetails.AutoGenerateColumns = false;
                dgDetails.ShowFooter = false;
                dgDetails.DataKeyField = dsTable.Tables[0].Rows[0]["DataKeyField"].ToString();
                dgDetails.CssClass = "tblResults";

                dgDetails.HeaderStyle.CssClass = "tblResultsHeader";
                if (!string.IsNullOrEmpty(Company.Current.Theme))
                {
                    dgDetails.HeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
                    dgDetails.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
                }
                dgDetails.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
                dgDetails.ItemStyle.CssClass = "ResultsStyle";
                dgDetails.AllowSorting = false;
                dgDetails.AllowPaging = false;

                foreach (DataRow dr in dsTable.Tables[1].Rows)
                {
                    if (Convert.ToBoolean(dr["ShowInTableOnly"]) || !Convert.ToBoolean(dr["ShowInPopUpOnly"]))
                    {
                        dgDetails.Columns.Add(CreateBoundColumn(dr));                        
                    }
                }
                List<InvoicePrint> invItems = InvoicePrint.GetInvoiceItems(Company.Current.CompanyID, int.Parse(q.InvoiceNo), OrderByPoNum);

                dgDetails.ItemDataBound += new DataGridItemEventHandler(dgDetails_Bind);
                dgDetails.DataSource = invItems;
                dgDetails.DataBind();

DataSet dsTable = null;
            dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint" + q.Job.JobScreen);
            if (dsTable.Tables[0].Rows.Count == 0)
            {
                dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint");
            }
            if (dsTable.Tables[0].Rows.Count > 0)
            {
                DataGrid dgDetails = new DataGrid();
                dgDetails.ID = "dgResults";
                dgDetails.Width = new Unit(dsTable.Tables[0].Rows[0]["Width"].ToString());
                dgDetails.BorderWidth = new Unit(dsTable.Tables[0].Rows[0]["BorderWidth"].ToString());

                switch (dsTable.Tables[0].Rows[0]["GridLines"].ToString().ToUpper())
                {
                    case "BOTH":
                        dgDetails.GridLines = GridLines.Both;
                        break;
                    case "HORIZONTAL":
                        dgDetails.GridLines = GridLines.Horizontal;
                        break;
                    case "NONE":
                        dgDetails.GridLines = GridLines.None;
                        break;
                    case "VERTICAL":
                        dgDetails.GridLines = GridLines.Vertical;
                        break;
                }
                dgDetails.AutoGenerateColumns = false;
                dgDetails.ShowFooter = false;
                dgDetails.DataKeyField = dsTable.Tables[0].Rows[0]["DataKeyField"].ToString();
                dgDetails.CssClass = "tblResults";

                dgDetails.HeaderStyle.CssClass = "tblResultsHeader";
                if (!string.IsNullOrEmpty(Company.Current.Theme))
                {
                    dgDetails.HeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
                    dgDetails.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
                }
                dgDetails.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
                dgDetails.ItemStyle.CssClass = "ResultsStyle";
                dgDetails.AllowSorting = false;
                dgDetails.AllowPaging = false;

                foreach (DataRow dr in dsTable.Tables[1].Rows)
                {
                    if (Convert.ToBoolean(dr["ShowInTableOnly"]) || !Convert.ToBoolean(dr["ShowInPopUpOnly"]))
                    {
                        dgDetails.Columns.Add(CreateBoundColumn(dr));                        
                    }
                }
                List<InvoicePrint> invItems = InvoicePrint.GetInvoiceItems(Company.Current.CompanyID, int.Parse(q.InvoiceNo), OrderByPoNum);

                dgDetails.ItemDataBound += new DataGridItemEventHandler(dgDetails_Bind);
                dgDetails.DataSource = invItems;
                dgDetails.DataBind();
DataSet-dsTable=null;
dsTable=DataUtils.GetTableProperties(Company.Current.CompanyID,“InvoicePrint”+q.Job.JobScreen);
if(dsTable.Tables[0].Rows.Count==0)
{
dsTable=DataUtils.GetTableProperties(Company.Current.CompanyID,“InvoicePrint”);
}
如果(数据表.Tables[0].Rows.Count>0)
{
DataGrid dgDetails=新DataGrid();
dgDetails.ID=“dgResults”;
dgDetails.Width=新单位(dsTable.Tables[0]。行[0][“Width”].ToString());
dgDetails.BorderWidth=新单位(数据表.Tables[0]。行[0][“BorderWidth”]。ToString());
开关(dsTable.Tables[0]。行[0][“网格线”]。ToString().ToUpper()
{
“两者”一案:
dgDetails.GridLines=网格线。两者都是;
打破
“水平”情况:
dgDetails.GridLines=GridLines.Horizontal;
打破
案例“无”:
DGDETAILES.GridLines=网格线。无;
打破
案例“垂直”:
dgDetails.GridLines=GridLines.Vertical;
打破
}
dgDetails.AutoGenerateColumns=false;
dgDetails.ShowFooter=false;
dgDetails.DataKeyField=dTable.Tables[0]。行[0][“DataKeyField”]。ToString();
dgDetails.CssClass=“tblResults”;
dgDetails.HeaderStyle.CssClass=“tblResultsHeader”;
如果(!string.IsNullOrEmpty(Company.Current.Theme))
{
dgDetails.HeaderStyle.ForeColor=System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
dgDetails.HeaderStyle.BackColor=System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
}
dgDetails.AlternatingItemStyle.CssClass=“ResultsStyleAlt”;
dgDetails.ItemStyle.CssClass=“ResultsStyle”;
dgDetails.AllowSorting=false;
dgDetails.AllowPaging=false;
foreach(数据表[1]中的数据行dr.行)
{
if(Convert.ToBoolean(dr[“ShowInTableOnly”])| |!Convert.ToBoolean(dr[“ShowInPopUpOnly”]))
{
dgDetails.Columns.Add(CreateBoundColumn(dr));
}
}
List invItems=InvoicePrint.GetInvoiceItems(Company.Current.CompanyID,int.Parse(q.InvoiceNo),OrderByPoNum);
dgDetails.ItemDataBound+=新的DataGridItemEventHandler(dgDetails_Bind);
dgDetails.DataSource=invItems;
dgDetails.DataBind();

但是分页符放在哪里?

您可以检查页面索引并将行样式设置为“之后分页符”,它将帮助您在打印某些记录后分页符
DataSet dsTable = null;
            dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint" + q.Job.JobScreen);
            if (dsTable.Tables[0].Rows.Count == 0)
            {
                dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint");
            }
            if (dsTable.Tables[0].Rows.Count > 0)
            {
                DataGrid dgDetails = new DataGrid();
                dgDetails.ID = "dgResults";
                dgDetails.Width = new Unit(dsTable.Tables[0].Rows[0]["Width"].ToString());
                dgDetails.BorderWidth = new Unit(dsTable.Tables[0].Rows[0]["BorderWidth"].ToString());

                switch (dsTable.Tables[0].Rows[0]["GridLines"].ToString().ToUpper())
                {
                    case "BOTH":
                        dgDetails.GridLines = GridLines.Both;
                        break;
                    case "HORIZONTAL":
                        dgDetails.GridLines = GridLines.Horizontal;
                        break;
                    case "NONE":
                        dgDetails.GridLines = GridLines.None;
                        break;
                    case "VERTICAL":
                        dgDetails.GridLines = GridLines.Vertical;
                        break;
                }
                dgDetails.AutoGenerateColumns = false;
                dgDetails.ShowFooter = false;
                dgDetails.DataKeyField = dsTable.Tables[0].Rows[0]["DataKeyField"].ToString();
                dgDetails.CssClass = "tblResults";

                dgDetails.HeaderStyle.CssClass = "tblResultsHeader";
                if (!string.IsNullOrEmpty(Company.Current.Theme))
                {
                    dgDetails.HeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
                    dgDetails.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
                }
                dgDetails.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
                dgDetails.ItemStyle.CssClass = "ResultsStyle";
                dgDetails.AllowSorting = false;
                dgDetails.AllowPaging = false;

                foreach (DataRow dr in dsTable.Tables[1].Rows)
                {
                    if (Convert.ToBoolean(dr["ShowInTableOnly"]) || !Convert.ToBoolean(dr["ShowInPopUpOnly"]))
                    {
                        dgDetails.Columns.Add(CreateBoundColumn(dr));                        
                    }
                }
                List<InvoicePrint> invItems = InvoicePrint.GetInvoiceItems(Company.Current.CompanyID, int.Parse(q.InvoiceNo), OrderByPoNum);

                dgDetails.ItemDataBound += new DataGridItemEventHandler(dgDetails_Bind);
                dgDetails.DataSource = invItems;
                dgDetails.DataBind();
请参阅下面的“打印”按钮上的代码

DataSet dsTable = null;
            dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint" + q.Job.JobScreen);
            if (dsTable.Tables[0].Rows.Count == 0)
            {
                dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint");
            }
            if (dsTable.Tables[0].Rows.Count > 0)
            {
                DataGrid dgDetails = new DataGrid();
                dgDetails.ID = "dgResults";
                dgDetails.Width = new Unit(dsTable.Tables[0].Rows[0]["Width"].ToString());
                dgDetails.BorderWidth = new Unit(dsTable.Tables[0].Rows[0]["BorderWidth"].ToString());

                switch (dsTable.Tables[0].Rows[0]["GridLines"].ToString().ToUpper())
                {
                    case "BOTH":
                        dgDetails.GridLines = GridLines.Both;
                        break;
                    case "HORIZONTAL":
                        dgDetails.GridLines = GridLines.Horizontal;
                        break;
                    case "NONE":
                        dgDetails.GridLines = GridLines.None;
                        break;
                    case "VERTICAL":
                        dgDetails.GridLines = GridLines.Vertical;
                        break;
                }
                dgDetails.AutoGenerateColumns = false;
                dgDetails.ShowFooter = false;
                dgDetails.DataKeyField = dsTable.Tables[0].Rows[0]["DataKeyField"].ToString();
                dgDetails.CssClass = "tblResults";

                dgDetails.HeaderStyle.CssClass = "tblResultsHeader";
                if (!string.IsNullOrEmpty(Company.Current.Theme))
                {
                    dgDetails.HeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
                    dgDetails.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
                }
                dgDetails.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
                dgDetails.ItemStyle.CssClass = "ResultsStyle";
                dgDetails.AllowSorting = false;
                dgDetails.AllowPaging = false;

                foreach (DataRow dr in dsTable.Tables[1].Rows)
                {
                    if (Convert.ToBoolean(dr["ShowInTableOnly"]) || !Convert.ToBoolean(dr["ShowInPopUpOnly"]))
                    {
                        dgDetails.Columns.Add(CreateBoundColumn(dr));                        
                    }
                }
                List<InvoicePrint> invItems = InvoicePrint.GetInvoiceItems(Company.Current.CompanyID, int.Parse(q.InvoiceNo), OrderByPoNum);

                dgDetails.ItemDataBound += new DataGridItemEventHandler(dgDetails_Bind);
                dgDetails.DataSource = invItems;
                dgDetails.DataBind();
 GridView1.UseAccessibleHeader = true;

GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;

GridView1.FooterRow.TableSection = TableRowSection.TableFooter;

GridView1.Attributes["style"] = "border-collapse:separate";

foreach (GridViewRow row in GridView1.Rows)

{

    if (row.RowIndex % 10 == 0 && row.RowIndex != 0)

    {

        row.Attributes["style"] = "page-break-after:always;";

    }

}

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.RenderControl(hw);

string gridHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");

StringBuilder sb = new StringBuilder();

sb.Append("<script type = 'text/javascript'>");

sb.Append("window.onload = new function(){");

sb.Append("var printWin = window.open('', '', 'left=0");

sb.Append(",top=0,width=1000,height=600,status=0');");

sb.Append("printWin.document.write(\"");

string style = "<style type = 'text/css'>thead {display:table-header-group;} tfoot{display:table-footer-group;}</style>";

sb.Append(style + gridHTML);

sb.Append("\");");

sb.Append("printWin.document.close();");

sb.Append("printWin.focus();");

sb.Append("printWin.print();");

sb.Append("printWin.close();");

sb.Append("};");

sb.Append("</script>");

ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

GridView1.DataBind();
GridView1.UseAccessibleHeader=true;
GridView1.HeaderRow.TableSection=TableRowSection.TableHeader;
GridView1.FooterRow.TableSection=TableRowSection.TableFooter;
GridView1.属性[“样式”]=“边框折叠:分离”;
foreach(GridView1.Rows中的GridViewRow行)
{
如果(row.RowIndex%10==0&&row.RowIndex!=0)
{
row.Attributes[“style”]=“之后的分页符:始终;”;
}
}
StringWriter sw=新的StringWriter();
HtmlTextWriter hw=新的HtmlTextWriter(sw);
GridView1.渲染控制(hw);
字符串gridHTML=sw.ToString().Replace(“\”,“”).Replace(System.Environment.NewLine,”);
StringBuilder sb=新的StringBuilder();
某人加上(“”);
sb.Append(“window.onload=new function(){”);
sb.Append(“var printWin=window.open(“”,,'left=0”);
sb.追加(“,顶部=0,宽度=1000,高度=600,状态=0');”;
sb.Append(“printWin.document.write(\”);
string style=“thead{display:table header group;}tfoot{display:table footer group;}”;
sb.Append(style+gridHTML);
某人加上“\”;”;
sb.Append(“printWin.document.close();”);
sb.Append(“printWin.focus();”);
sb.Append(“printWin.print();”);
sb.Append(“printWin.close();”);
某人加上(“};”;
某人加上(“”);
RegisterStartupScript(this.GetType(),“GridPrint”,sb.ToString());
GridView1.DataBind();

希望有帮助

您可以检查页面索引并将行样式设置为“打印后分页符”,这将帮助您在打印某些记录后分页符
DataSet dsTable = null;
            dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint" + q.Job.JobScreen);
            if (dsTable.Tables[0].Rows.Count == 0)
            {
                dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint");
            }
            if (dsTable.Tables[0].Rows.Count > 0)
            {
                DataGrid dgDetails = new DataGrid();
                dgDetails.ID = "dgResults";
                dgDetails.Width = new Unit(dsTable.Tables[0].Rows[0]["Width"].ToString());
                dgDetails.BorderWidth = new Unit(dsTable.Tables[0].Rows[0]["BorderWidth"].ToString());

                switch (dsTable.Tables[0].Rows[0]["GridLines"].ToString().ToUpper())
                {
                    case "BOTH":
                        dgDetails.GridLines = GridLines.Both;
                        break;
                    case "HORIZONTAL":
                        dgDetails.GridLines = GridLines.Horizontal;
                        break;
                    case "NONE":
                        dgDetails.GridLines = GridLines.None;
                        break;
                    case "VERTICAL":
                        dgDetails.GridLines = GridLines.Vertical;
                        break;
                }
                dgDetails.AutoGenerateColumns = false;
                dgDetails.ShowFooter = false;
                dgDetails.DataKeyField = dsTable.Tables[0].Rows[0]["DataKeyField"].ToString();
                dgDetails.CssClass = "tblResults";

                dgDetails.HeaderStyle.CssClass = "tblResultsHeader";
                if (!string.IsNullOrEmpty(Company.Current.Theme))
                {
                    dgDetails.HeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
                    dgDetails.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
                }
                dgDetails.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
                dgDetails.ItemStyle.CssClass = "ResultsStyle";
                dgDetails.AllowSorting = false;
                dgDetails.AllowPaging = false;

                foreach (DataRow dr in dsTable.Tables[1].Rows)
                {
                    if (Convert.ToBoolean(dr["ShowInTableOnly"]) || !Convert.ToBoolean(dr["ShowInPopUpOnly"]))
                    {
                        dgDetails.Columns.Add(CreateBoundColumn(dr));                        
                    }
                }
                List<InvoicePrint> invItems = InvoicePrint.GetInvoiceItems(Company.Current.CompanyID, int.Parse(q.InvoiceNo), OrderByPoNum);

                dgDetails.ItemDataBound += new DataGridItemEventHandler(dgDetails_Bind);
                dgDetails.DataSource = invItems;
                dgDetails.DataBind();
请参阅下面的“打印”按钮上的代码

DataSet dsTable = null;
            dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint" + q.Job.JobScreen);
            if (dsTable.Tables[0].Rows.Count == 0)
            {
                dsTable = DataUtils.GetTableProperties(Company.Current.CompanyID, "InvoicePrint");
            }
            if (dsTable.Tables[0].Rows.Count > 0)
            {
                DataGrid dgDetails = new DataGrid();
                dgDetails.ID = "dgResults";
                dgDetails.Width = new Unit(dsTable.Tables[0].Rows[0]["Width"].ToString());
                dgDetails.BorderWidth = new Unit(dsTable.Tables[0].Rows[0]["BorderWidth"].ToString());

                switch (dsTable.Tables[0].Rows[0]["GridLines"].ToString().ToUpper())
                {
                    case "BOTH":
                        dgDetails.GridLines = GridLines.Both;
                        break;
                    case "HORIZONTAL":
                        dgDetails.GridLines = GridLines.Horizontal;
                        break;
                    case "NONE":
                        dgDetails.GridLines = GridLines.None;
                        break;
                    case "VERTICAL":
                        dgDetails.GridLines = GridLines.Vertical;
                        break;
                }
                dgDetails.AutoGenerateColumns = false;
                dgDetails.ShowFooter = false;
                dgDetails.DataKeyField = dsTable.Tables[0].Rows[0]["DataKeyField"].ToString();
                dgDetails.CssClass = "tblResults";

                dgDetails.HeaderStyle.CssClass = "tblResultsHeader";
                if (!string.IsNullOrEmpty(Company.Current.Theme))
                {
                    dgDetails.HeaderStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.TextColor);
                    dgDetails.HeaderStyle.BackColor = System.Drawing.ColorTranslator.FromHtml(Company.Current.Theme);
                }
                dgDetails.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
                dgDetails.ItemStyle.CssClass = "ResultsStyle";
                dgDetails.AllowSorting = false;
                dgDetails.AllowPaging = false;

                foreach (DataRow dr in dsTable.Tables[1].Rows)
                {
                    if (Convert.ToBoolean(dr["ShowInTableOnly"]) || !Convert.ToBoolean(dr["ShowInPopUpOnly"]))
                    {
                        dgDetails.Columns.Add(CreateBoundColumn(dr));                        
                    }
                }
                List<InvoicePrint> invItems = InvoicePrint.GetInvoiceItems(Company.Current.CompanyID, int.Parse(q.InvoiceNo), OrderByPoNum);

                dgDetails.ItemDataBound += new DataGridItemEventHandler(dgDetails_Bind);
                dgDetails.DataSource = invItems;
                dgDetails.DataBind();
 GridView1.UseAccessibleHeader = true;

GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;

GridView1.FooterRow.TableSection = TableRowSection.TableFooter;

GridView1.Attributes["style"] = "border-collapse:separate";

foreach (GridViewRow row in GridView1.Rows)

{

    if (row.RowIndex % 10 == 0 && row.RowIndex != 0)

    {

        row.Attributes["style"] = "page-break-after:always;";

    }

}

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.RenderControl(hw);

string gridHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");

StringBuilder sb = new StringBuilder();

sb.Append("<script type = 'text/javascript'>");

sb.Append("window.onload = new function(){");

sb.Append("var printWin = window.open('', '', 'left=0");

sb.Append(",top=0,width=1000,height=600,status=0');");

sb.Append("printWin.document.write(\"");

string style = "<style type = 'text/css'>thead {display:table-header-group;} tfoot{display:table-footer-group;}</style>";

sb.Append(style + gridHTML);

sb.Append("\");");

sb.Append("printWin.document.close();");

sb.Append("printWin.focus();");

sb.Append("printWin.print();");

sb.Append("printWin.close();");

sb.Append("};");

sb.Append("</script>");

ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

GridView1.DataBind();
GridView1.UseAccessibleHeader=true;
GridView1.HeaderRow.TableSection=TableRowSection.TableHeader;
GridView1.FooterRow.TableSection=TableRowSection.Ta