C# - How to print grid view data with image by JavaScript()?


C# - How to print grid view data with image by JavaScript()?

C# - Print Image In Gridview

In this post I will show how to print data with images from GridView using javascript. Find the source code below:-

C# - How to print grid view data with image by JavaScript()?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>C# - How to print grid view data with div by JavaScript()?</title>

    <form id="form1" runat="server">
        <div id="gvDiv">
                <asp:Image ID="Image1" ImageUrl="~/sample2.jpg" runat="server" /><br />
                <br />
            <asp:GridView ID="gvPrint" runat="server">
        <br />
        <asp:Button ID="btnPrint" runat="server" Text="Print Details" />

using System;

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;

public partial class _Default : System.Web.UI.Page
    private void Display()
    protected void Page_Load(object sender, EventArgs e)
        DataTable dtEmployee = new DataTable();

        dtEmployee.Columns.Add("EmpId", typeof(int));
        dtEmployee.Columns.Add("Name", typeof(string));
        dtEmployee.Columns.Add("Address", typeof(string));
        dtEmployee.Columns.Add("Date", typeof(DateTime));

        dtEmployee.Rows.Add(25, "Rk", "Gurgaon", DateTime.Now);
        dtEmployee.Rows.Add(50, "Sachin", "Noida", DateTime.Now);
        dtEmployee.Rows.Add(10, "Nitin", "Noida", DateTime.Now);
        dtEmployee.Rows.Add(21, "Aditya", "Meerut", DateTime.Now);
        dtEmployee.Rows.Add(100, "Mohan", "Banglore", DateTime.Now);

        gvPrint.DataSource = dtEmployee;

        string printScript =
         @"function PrintGridView()
            var gridInsideDiv = document.getElementById('gvDiv');
            var printWindow = window.open('gview.htm','PrintWindow','letf=50,top=50,width=400,height=300,toolbar=1,scrollbars=1,status=1');

        this.ClientScript.RegisterStartupScript(Page.GetType(), "PrintGridView", printScript.ToString(), true);
        btnPrint.Attributes.Add("onclick", "PrintGridView();");      

Download source code click here..

C# - How to print grid view data with image by JavaScript()? Reviewed by Ravi Kumar on 11:56 AM Rating: 5

1 comment:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form


Email *

Message *

Powered by Blogger.