Printing part of page. - Asked By Danish Shaikh on 05-May-08 02:32 AM

Use <DIV> to enclose ur grid.
e.g.:

<div id="areaToPrint">
ur grid inside in this tag
</div>

then add javascript to ur page to print ur grid :

<script>
function printDiv()
{
   var divToPrint=document.getEelementById('
areaToPrint');
  newWin= window.open("");
  newWin.document.write(
divToPrint.outerHTML);
  newWin.print();
  newWin.close();
}
</script>




Try this - Asked By sri sri on 05-May-08 02:33 AM

Hi,
Place a print button in your page.
on clicking the button , open a popup containg only the grid,
bind that grid in the page load.
 then call the print function.
try this..

/------ Aspx page -----/
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>   
    </div>
    </form>
</body>
</html>
<script type="text/javascript" language="javascript">
window.print();
</script>

Try this - Asked By SP on 05-May-08 02:36 AM

Try the following links with code ::

http://groups.google.com/group/a-c-net/browse_thread/thread/2957c343959e1c24
http://www.codeproject.com/KB/aspnet/RussprintTemplates.aspx

Try this to print a datagrid - Asked By Sagar P on 05-May-08 02:36 AM

<script language=javascript>
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;
}
</script>

<div id="divPrint">
<asp:datagrid>
.....
.....
.....
</asp:datagrid>
</div>
<asp:button ID="btnPrint" onClick="javascript:CallPrint('divPrint');" Runat=Server />

Or you can gor thr this;

http://www.codeproject.com/KB/aspnet/Print_Grid.aspx

http://www.devx.com/tips/Tip/27626

Best Luck!!!!!!!!

Sujit.

print specific portions using only CSS - Asked By mv ark on 05-May-08 02:50 AM
By using seperate stylesheets for screen and printing in the same page, you can hide or show specific portions for each MEDIA
<link rel="stylesheet" type="text/css" href="path/to/screen.css" media="screen" /> <link rel="stylesheet" type="text/css" href="path/to/print.css" media="print" />

The above 2 lines mean that when the page is requested from a web browser, the screen.css file will dictate the style of the page(s) and when printed or print previewed, the print.css file will dictate the style of the page.

In the stylesheet specifically meant for the Printer, specify the style for all parts of the page except the grid as display:none

Check these links for more info on this technique:
http://www.designplace.org/tutorials.php?page=1&c_id=27
http://www.alistapart.com/articles/goingtoprint/
http://www.4guysfromrolla.com/webtech/061103-1.shtml
check these... - Asked By Santhosh N on 05-May-08 02:52 AM

check this link which explains how to preview only certain area for printing ..

http://www.codeproject.com/KB/aspnet/PrintPreview.aspx

and this one too which has great samples in windows app though..

http://www.c-sharpcorner.com/UploadFile/mgold/HowToPrintaDataGridinCsHARPand.NET11212005060838AM/HowToPrintaDataGridinCsHARPand.NET.aspx

Transfer grid data to excel - Asked By Sunil Lakshkar on 05-May-08 06:22 AM

Hi,

You can put a button and can transfer your grid data to an excel file on click on that button and then can take print out.

You can call following fuction on cliick of that button

protected void btnExport_Click(object sender, EventArgs e)

{

Response.Clear();

string strHeading = "";

//Response.AddHeader("content-disposition", "attachment; filename=ArchiveReport.xls");

Response.Charset = "";

// If you want the option to open the Excel file without saving than

// comment out the line below

// Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

if (gridArchiveViewGrid.Visible)

{

Response.AddHeader("content-disposition", "attachment; filename=ArchiveReport.xls");

strHeading = "<table class='TableFont' cellspacing='0' cellpadding='" + gridArchiveViewGrid.Columns.Count + "' style='background-color:#ccffff; border:0px;width:100%;' ><tr align='center'><TH colspan='" + gridArchiveViewGrid.Columns.Count + "'><b>LogicaCMG</b></TH></tr><tr align='center'><TH colspan='" + gridArchiveViewGrid.Columns.Count + "'><b>Archive report for period " + txt_FromDate.Value + " to " + txt_ToDate.Value + "</b></TH></tr></table>";

stringWrite.WriteLine(strHeading);

}

else

{

Response.AddHeader("content-disposition", "attachment; filename=Report_NotSubmitted.xls");

strHeading = "<table class='TableFont' cellspacing='0' cellpadding='" + gridYetToSubmitGrid.Columns.Count + "' style='background-color:#ccffff; border:0px;width:100%;' runat='server' ><tr align='center'><TH colspan='" + gridYetToSubmitGrid.Columns.Count + "'><b>LogicaCMG</b></TH></tr><tr align='center'><TH colspan='" + gridYetToSubmitGrid.Columns.Count + "'><b>report for Resource who has not submitted Timesheets for period " + txt_FromDate.Value + " to " + txt_ToDate.Value + "</b></TH></tr></table>";

stringWrite.WriteLine(strHeading);

}

System.Web.UI.HtmlTextWriter htmlWrite =

new HtmlTextWriter(stringWrite);

//gridArchiveViewGrid.RenderBeginTag(htmlWrite);

if (gridArchiveViewGrid.Visible)

{

gridArchiveViewGrid.RenderControl(htmlWrite);

}

else gridYetToSubmitGrid.RenderControl(htmlWrite);

//gridArchiveViewGrid.RenderEndTag(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}