<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private DataTable GetDataTable()
{
//create table
DataTable dt = new DataTable("Product");
dt.Columns.Add("ProductID", Type.GetType("System.Int32"));
dt.Columns.Add("ProductName", Type.GetType("System.String"));
//create fields
DataColumn[] pk = new DataColumn[1];
pk[0] = dt.Columns["ProductID"];
dt.PrimaryKey = pk;
dt.Columns["ProductID"].AutoIncrement = true;
dt.Columns["ProductID"].AutoIncrementSeed = 1;
dt.Columns["ProductID"].ReadOnly = true;
//fill rows
DataRow dr;
for (int x = 1; x <= 10; x++)
{
//make every other one different
if (Math.IEEERemainder(x, 2) == 0)
{
dr = dt.NewRow();
dr["ProductName"] = "Riss";
dt.Rows.Add(dr);
}
else
{
dr = dt.NewRow();
dr["ProductName"] = "Product";
dt.Rows.Add(dr);
}
}
return dt;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = GetDataTable();
GridView1.DataBind();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=400,height=400,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divPrint">
<asp:GridView ID="GridView1" runat="server" />
</div>
<input type="button" value="print " id="btnPrint" runat="Server" onclick="javascript:CallPrint('divPrint')" />
</form>
</body>
</html>
use html (<input type="button">) button instead of <asp:button>>.
A directory of ASP.NET tutorials,ASP.NET Codebook, applications, scripts, assemblies and articles for the novice to professional developer
Blog Archive
-
▼
2009
(29)
-
►
April
(9)
- How To Read xml using JQuery
- jQuery Ajax call and result XML parsing in asp.net...
- How To Include Content of One Page To another Page...
- How To Select Value of gridview row using javascri...
- how to convert web page to pdf
- ASP.NET and Ajax - using XmlHttpRequest
- How To Move Selected Record From One GridView to a...
- How To Extract Number from string
- How To create Cascade dropdownlist using asp.net c...
-
►
March
(18)
- Parent Child Relationship in Javascript
- How To Create Composite Control
- How To find control inside EmptyTemplate
- jQuery in 15 minutes
- How To Create MultiColum Dropdownlist using DropDo...
- How To Create Multi Column Dropdownlist
- How To Create control at runtime using javascript
- How to Move a Text Box on Button Click
- How To attach event to runtime created control
- How To Find Position of Span Tag
- How To add event to runtime created control -Javas...
- How To Display Hierarchical Data in the DropDownLi...
- Real World GridView: Excel-like Frozen Headers for...
- GridView Sorting And Paging
- How to create a Setup project for a Windows Servic...
- 101 LINQ Samples
- How to open ModalPopup inside ModalPopup
- How to Retrieve Hardware and softwarte information...
-
►
April
(9)
-
►
2008
(490)
-
►
December
(7)
- Creating javascript alerts in ASP.NET with UpdateP...
- ASP.net TreeView Tips and Trics
- How to make your ASP.Net label multilin
- How To Create TextBox Control Dynamically at Runti...
- How To Use RegularExpressionValidator with FileUpl...
- How To Add Multiple UserControls using RequiredFie...
- How To Make Clickable image
-
►
October
(11)
- How To Call .net Webservice using Javascript
- Calling page methods from javascript using ASP.NET...
- How To Use Web Service Behavior in an ASP.NET Page...
- How To Load xml string into DataSet
- How to convert from XmlTextWriter to String?
- Error: Timeout expired. The timeout period elapsed...
- Using an XML file for your ASP.NET settings
- Two approaches to redirection in ASP.NET
- read, write and save values in app.config file
- Adding tooltips to GridView headers
-
►
December
(7)
Wednesday, February 27, 2008
Printing GridView from ASp.net
Labels:
ASP.NET
Subscribe to:
Post Comments (Atom)
|
Over the years I have collected some best asp.net code while googling........I hope
this information is as useful to you as it has been for me("If you find my post
contains a reference to a third party World Wide Web site, I am providing this information
as a convenience to you.I cannot make any representations regarding the quality,safety,
or suitability of any software or information found there")
|








0 comments:
Post a Comment