<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridView Print</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns = "false" Font-Names = "Arial"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"
HeaderStyle-BackColor = "green" AllowPaging = "false">
<Columns>
<asp:BoundField ItemStyle-Width = "150px" DataField = "ENO"
HeaderText = "ENO" />
<asp:BoundField ItemStyle-Width = "150px" DataField = "ENAME"
HeaderText = "ENAME"/>
<asp:BoundField ItemStyle-Width = "150px" DataField = "JOB"
HeaderText = "JOB"/>
</Columns>
</asp:GridView>
</div>
<br />
<asp:Button ID="btnPrint" runat="server" Text="Print" onclick = "Gridprint();""/>
</form>
</html>
this my aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using Oracle.DataAccess;
using Oracle.DataAccess.Client;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
BindGridview();
}
protected void BindGridview()
{
OracleDataAdapter adapter = new OracleDataAdapter();
DataSet ds = new DataSet();
string sql = null;
string connetionString = ("Data Source=TEST;User ID=TEST; Password =TEST ");
sql = "select * from emp";
OracleConnection connection = new OracleConnection(connetionString);
connection.Open();
OracleCommand command = new OracleCommand(sql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
command.Dispose();
connection.Close();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
/*Verifies that the control is rendered */
}
protected void Print(object sender, EventArgs e)
{
GridView1.UseAccessibleHeader = true;
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
GridView1.Attributes["style"] = "border-collapse:separate";
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowIndex % 10 == 0 && row.RowIndex != 0)
{
row.Attributes["style"] = "page-break-after:always;";
}
}
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.RenderControl(hw);
string gridHTML = sw.ToString().Replace("\"", "'").Replace(System.Environment.NewLine, "");
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printWin = window.open('', '', 'left=0");
sb.Append(",top=0,width=1000,height=600,status=0');");
sb.Append("printWin.document.write(\"");
string style = "<style type = 'text/css'>thead {display:table-header-group;} tfoot{display:table-footer-group;}</style>";
sb.Append(style + gridHTML);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();");
sb.Append("};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
GridView1.AllowPaging = true;
GridView1.DataBind();
}
}
can any one help me what is wrong in this
Error2The server tag is not well formed.