mohammed shamsheer

mohammed shamsheer

  • 1.2k
  • 394
  • 139.9k

The table must contain row sections in order of header, body

Jan 14 2014 4:25 AM
I am using printwebhelper method for printing the gridview content
i just pass gridview to the class
the class is :
<pre lang="c#">public static void PrintWebControl(Control ctrl, string Script, GridView SalesGridView)
{
//if (System.Web.HttpContext.Current.(string)Session["isgrid"] == "grid")
//{
// GridView grid = (GridView)ctrl;
// grid.AllowPaging = false;
// grid.DataBind();
if (SalesGridView.Rows.Count &gt; 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("&lt;script&gt;window.print();&lt;/script&gt;");
string style = "&lt;style type = 'text/css'&gt;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; &lt;/style&gt;";
HttpContext.Current.Response.Write(style);
HttpContext.Current.Response.End();
}
}
</pre>
but when it reached
<pre lang="cs">pg.DesignerInitialize();
pg.RenderControl(htmlWrite);</pre>
line it showing the error
The table must contain row sections in order of header, body, then footer