I am using printwebhelper method for printing the gridview content
i just pass gridview to the class
the class is :
Code
public static void PrintWebControl(Control ctrl, string Script, GridView SalesGridView)HTML / XML
{
//if (System.Web.HttpContext.Current.(string)Session["isgrid"] == "grid")
//{
// GridView grid = (GridView)ctrl;
// grid.AllowPaging = false;
// grid.DataBind();
if (SalesGridView.Rows.Count > 0)
{
//}
SalesGridView.UseAccessibleHeader = true;
SalesGridView.HeaderRow.TableSection = TableRowSection.TableHeader;
SalesGridView.FooterRow.TableSection = TableRowSection.TableFooter;
SalesGridView.Attributes["style"] = "border-collapse:separate";
foreach (GridViewRow row in SalesGridView.Rows)
{
if (row.RowIndex % 30 == 0 && row.RowIndex != 0)
{
row.Attributes["style"] = "page-break-after:always;";
}
}
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
string style = "<style type = 'text/css'>td { padding: 4px; border: solid 1px #c1c1c1; color: #474545; font-family:Arial; font-size:12px } th { padding: 2px 2px; color: #3e4d9e; background: #e0d7f4 ; font-family:Arial; text-align:left;text-indent:10px; font-size:14px ;border-top: solid 1px #a99cec; border-left:none;border-right:none; border-bottom:none }{ width: 100%;background-color: #fff; margin: 5px 0 10px 0; border-top: solid 1px #a99cec; border-left:solid 1px #a99cec;border-right:solid 1px #a99cec;font-family:Arial; font-size:15px; </style>";
HttpContext.Current.Response.Write(style);
HttpContext.Current.Response.End();
}
}but when it reached
Code
pg.DesignerInitialize(); pg.RenderControl(htmlWrite);
line it showing the error
The table must contain row sections in order of header, body, then footer

Answers
Know the answer? Post it. Somebody with the same question will find it here.