Print All pages of Grid View with Preint Preview

  • Thread starter Thread starter Kelkars
  • Start date Start date
K

Kelkars

Guest
I am trying to Print All the pages of my Grid View Results using the below code but facing the following issue -

Control _gridResults of type GridView must be placed inside a form tag with runat=server.

Upon searching accross the net, i foudn the solution as need of overriding the below method =

public override void VerifyRenderingInServerForm(Control control){
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */}

But, it doesnt seem to be solving the problem.

gridResults = (id of my Grid View)

Below is my Code -


protected void btnPrintAll_Click(object sender, EventArgs e)
{
gridAppInventory.AllowPaging = false;
gridAppInventory.DataBind();

StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gridAppInventory.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(\"");
sb.Append(gridHTML);

sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();};");
sb.Append("</script>");

// Define the name and type of the client scripts on the page.
String csname = "PrintAllScript";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager ClientScript = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!ClientScript.IsStartupScriptRegistered(cstype, csname))
{
ClientScript.RegisterStartupScript(this.GetType(), csname, sb.ToString());
}
gridAppInventory.AllowPaging = true;

gridAppInventory.DataBind();
}


Kindly suggest if any issues in the same.


SVK

Continue reading...
 
Back
Top