protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = System.DateTime.Now.ToShortDateString();
OracleDataAdapter adapter = new OracleDataAdapter();
DataSet ds = new DataSet();
//int i = 0;
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();
grdUserList.DataSource = ds.Tables[0];
grdUserList.DataBind();
}
protected void Print(object sender, EventArgs e)
{
grdUserList.UseAccessibleHeader = true;
grdUserList.HeaderRow.TableSection = TableRowSection.TableHeader;
grdUserList.FooterRow.TableSection = TableRowSection.TableFooter;
grdUserList.Attributes["style"] = "border-collapse:separate";
foreach (GridViewRow row in grdUserList.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);
grdUserList.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());
grdUserList.DataBind();
}
int tempcounter = 0;
protected void grdUserList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
tempcounter = tempcounter + 1;
if (tempcounter == 10)
{
e.Row.Attributes.Add("style", "page-break-after: always;");
tempcounter = 0;
}
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/*Verifies that the control is rendered */
}
}
HI
I AM GETTING JavaScript runtime error: Unable to get property 'document' of undefined or null reference ERROR
what i am trying to do is print the gridview data
so can any one help me