title: grid view printing with table in asp.net
body: <p>i am using visual studio 2008 and sql server 2008</p>
  
  <p>i want to print my <strong>"gridview with table"</strong> using a button 
  in asp.net 3.5 
  code has three part first this is from my default page </p>
  
  <pre><code> protected void btnPrint_Click(object sender, EventArgs e)
  {
      Session["ctrl"] = Panel1;
      ClientScript.RegisterStartupScript(this.GetType(), "onclick",
          "&lt;script language=javascript&gt;window.open('Print.aspx','PrintMe','height=300px,width=300px,scrollbars=1');&lt;/script&gt;");
      PrintHelper.PrintWebControl(Panel1);
  }
  </code></pre>
  
  <p>this code this from print page </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Control ctrl = (Control)Session["ctrl"];
      PrintHelper.PrintWebControl(ctrl);
  }
  </code></pre>
  
  <p>and this is my print helper class </p>
  
  <pre><code> public PrintHelper()
  {
  }
  
  public static void PrintWebControl(Control ctrl)
  {
      PrintWebControl(ctrl, string.Empty);
  }
  
  public static void PrintWebControl(Control ctrl, string Script)
  {
      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;");
      HttpContext.Current.Response.End();
  }
  </code></pre>
  
  <p>please help me out </p>