title: How to print and print preview dialog box display?
body: <p>I created a web application for college.  I want to add print and print preview button to printing result of student.  Which classes are used for printing  a form?</p>
  
  <p>My print and print preview button coding is below:</p>
  
  <pre><code>protected void btnprint_Click(object sender, EventArgs e)
  {
      if (this.gridcontrol != null)
      {
          GridPrintDocument gpd = new GridPrintDocument(this.gridcontrol, true);
  
          PrintDialog pritdlg = new PrintDialog();
          pritdlg.Document = gpd;
  
          if (pritdlg.ShowDialog() == DialogResult.OK)
              gpd.Print();
      }
      else
      {
          lblstatus.Text="An error occurred attempting to print the grid ";
      }
  }
  
  protected void btnprntprew_Click(object sender, EventArgs e)
  {
      if (this.gridcontrol != null)
      {
          //Uses the default printer.
          GridPrintDocument gpd = new GridPrintDocument(this.gridcontrol, true);
          PrintPreviewDialog pripredlg = new PrintPreviewDialog();
          pripredlg.Document = gpd;
          pripredlg.ShowDialog();
      }
      else
      {
          lblstatus.Text = "An error occurred attempting to preview the grid ";
      }
  }
  </code></pre>