Question

So i have this code

    AuditTrailGV.AllowPaging = false;
    AuditTrailGV.DataSource = (DataSet)ViewState["audit"];
    AuditTrailGV.DataBind();
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    AuditTrailGV.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(\"");
    sb.Append(gridHTML);
    sb.Append("\");");
    sb.Append("printWin.document.close();");
    sb.Append("printWin.focus();");
    sb.Append("printWin.print();");
    sb.Append("printWin.close();};");
    sb.Append("</script>");
    ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
    AuditTrailGV.AllowPaging = true;
    AuditTrailGV.DataSource = (DataSet)ViewState["audit"];
    AuditTrailGV.DataBind();

This code prints the details inside a gridview like this

enter image description here

my problem is that i need to add texts above the grid so it should look like this
enter image description here

I need to add the texts above upon printing (the elements inside free hand drawn circle :p)

any help? thanks :)

No correct solution

OTHER TIPS

Could you please try like this?

...
StringWriter sw = new StringWriter();
sw.WriteLine("SYSTEM NAME");
sw.WriteLine("Audit Trail\t\tDate " + DateTime.Now);
HtmlTextWriter hw = new HtmlTextWriter(sw);
AuditTrailGV.RenderControl(hw);
...

I hope this will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top