What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7433 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Print Gridview Data in asp.net using javascript. ...
Bageshkumarbagi

Print Gridview Data in asp.net using javascript.

 Code Snippet posted by: Bageshkumarbagi | Posted on: 10/19/2012 | Category: ASP.NET Codes | Views: 1046 | Status: [Member] | Points: 40 | Alert Moderator   


======html asp.net code========

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Print Gridview Data in asp.net</title>
<script type="text/javascript">
function PrintGridData() {
var prtGrid = document.getElementById('<%=gv.ClientID %>');
prtGrid.border = 0;
var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write(prtGrid.outerHTML);
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div><b>Print Gridview Data</b>
<br />
<br /><asp:GridView ID="gv" runat="server" >
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White"/></asp:GridView>
<input type="button" id="btnPrint" value="Print" onclick="PrintGridData()" />
</div>
</form>
</body>
</html>

==========C# code================

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
SqlConnection con = new SqlConnection("Data Source=SYNCGDC0491;Initial Catalog=ReportServer;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Select TOP 20 id,name,location from emp", con);
SqlDataReader dr = cmd.ExecuteReader();
gv.DataSource = dr;
gv.DataBind();
con.Close();
}
catch (Exception ea)
{
Response.Write(ea.Message);
}
}
}
}

=======database design===========
table name is emp
id int
name varchar(50)
location varchar(50)
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 1:51:00 AM