ASP.NET - Print Datalist Values

Asked By Shamnad K
25-Jul-11 12:17 AM
I wanna print the records in a datalist....
  TSN ... replied to Shamnad K
25-Jul-11 12:21 AM
hi..

Print a DataGrid Alone from an ASP.NET Web Page
Ever wanted to print a DataGrid alone from an ASP.NET http://www.devx.com/tips/Tip/27626# page? Put an <asp:DataGrid> tag inside the tag does the trick. Here are the steps involved:
  1. Enclose the <asp:datagrid></asp:datagrid> tag inside the <div></div> tag.
  2. Write a JavaScript function which takes care of printing the content from <div> tag.
Here's an example:

<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 />


hi i have shown this for Datagrid try this for datalist sample.. if any problems ping back...
  Bala Marish replied to Shamnad K
25-Jul-11 12:24 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 />


You can try this:-

OnClientClick="CallPrint('divPrint');"

instead of
onClick="javascript:CallPrint('divPrint');"
  Vickey F replied to Shamnad K
25-Jul-11 12:30 AM

If you want to print selected table or object in web page then you can use Jquery.

By adding jquery plugin you can easily print any selected object in web page-

After adding print plugin to your page, use this code-

var o = $("#DataListName");
o.jqprint();

For more information about print plugin follow this link-

http://plugins.jquery.com/plugin-tags/print

Hope this will help you.

  Sreekumar P replied to Shamnad K
25-Jul-11 12:40 AM
It has to work! Here is the code I have just tested and it works, I have tested it on IE, Firefox, Opera. I have put styles in the same document for clarity.

<!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>
<title>Hide print button</title>
<style type="text/css" media="screen">
.PrintButton{
display:block;
}
</style>
<style type="text/css" media="print">
.PrintButton{
display:none;
}
</style>
</head>
<body>
<form id="PrintForm" action="Print.htm">
<h1>
<asp:datagrid>
.....
.....
.....
</asp:datagrid>
<br />
<input id="btnPrint" type="button" value="Print page" class="PrintButton" onclick="window.print();" />
</form>
</body>
</html>

  Reena Jain replied to Shamnad K
25-Jul-11 03:52 AM
Hi,

Here are the steps involved:
  1. Enclose the <asp:dataList></asp:dataList> tag inside the <div></div> tag.
  2. Write a JavaScript function which takes care of printing the content from <div> tag.
Here's an example:

<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:dataList>
.....
.....
.....
</asp:dataList>
</div>
<asp:button ID="btnPrint" onClick="javascript:CallPrint('divPrint');" Runat=Server />

hope this will help you
Create New Account
help
how to print datagrid data in asp.net end of post See http: / / www.netomatix.com / development / gridviewprinting.aspx for complete code and demo. Also . Print a DataGrid Alone from an ASP.NET Web Page URL : http: / / www.devx.com / tips / Tip / 27626 Ever wanted to print a DataGrid alone from an ASP.NET Web page? Put an <asp:DataGrid> tag inside the tag
print a asp.net page Helo to all i am making an asp.net web application I am printing a page <input type = "button" value = "Print this page" onClick = "window.print()"> But whats happening after print button i also coming. . I don't session content to the document 3. call js on load for print the documetn Base page aspx <%@ Page Language = "C#" MasterPageFile = "~ / MasterPage.master" AutoEventWireup = "true" CodeFile = "Default2.aspx.cs" Inherits = "Default2
javascript print break < script language = "javascript" type = "text / javascript"> function getPrint(print_area) { if (confirm( "Are you sure, you want to print?" )) { var printContent = document.getElementById innerHTML); printWindow.document.close(); printWindow.focus(); printWindow.print(); printWindow.close(); } } - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - < / script > < div id = "divSchool" style = "page-break-before: always"> < asp : Repeater ID = "rptcalender" runat = "server" OnItemDataBound = "rptcalender_ItemDataBound"> < ItemTemplate > < asp : Label ID Visible = "False" / > - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - the above coding is when user going to click printButton it will call javascript function, it is passing some div value, here im saying that print particular div information, here i need to print page break, i want to break page, becoz it is not clear plz plz plz. . . . Hi
How to print a datagid in ASP.NET web application? Hi, I need to print a datagrid in asp.Net web application, the datagrid paging is true and i need to print all the pages. please help Thanks, shankar Ever wanted to print a DataGrid alone from an ASP.NET Web page? Put an <asp:DataGrid> tag inside the tag does the trick. Here