Click here to Skip to main content
12,762,900 members (36,016 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 16 Jun 2013

Print DataGridView data or particular control's data from web page

, 17 Jun 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip explains how to print a particular web control's data from a web page.


This tip explains how to print a particular web control's data from a web page.


I have tried to open a new page and use JavaScript to print the web page, but all the web page controls are printed using

Using the code

function PrintCasedata() {
// var prtGrid1 = document.getElementById("<%= GridView1.ClientID %>");
var prtGrid1 = document.getElementById("<%= Panel1.ClientID %>");

// document.getElementById("GridView1");
//prtGrid1.border = 1;
var prtwin ='', 'PrintCasedata', 

On this button I have added code tp print the DataGridView.

<asp:Button ID="btnPrint" runat="server" 
  OnClick="btnPrint_Click" Text="Print" 
  Height="26px" Width="42px" />

Use the following code at codebehind:

protected void btnPrint_Click(object sender, EventArgs e)
  //      this.GetType(), "mymessage", "Myprint(" + ");", true);
  ScriptManager.RegisterStartupScript(this, this.GetType(),
          "mymessage", "PrintCasedata(" + ");", true);

Using this code we can print the formatted web page,  i.e. we want the logo on the print, the date, and user name. So we need to collect all controls which need to print on one panel or group box. And then replace the id in GroupControlID.

var prtGrid1 = document.getElementById("<%= GroupControlID.ClientID %>");


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer MogyaSoft
India India
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170217.1 | Last Updated 17 Jun 2013
Article Copyright 2013 by Mogya
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid