Answered by:
Gridview Header on each printed Page with the page title

Question
-
User-1746098369 posted
Dear Friends
last few Days I have been struggling with the printing from an aspx page in which I have the Data in a gridview and the page heading of from Dat to To Date duration.
I have to print the page with the page heading and the gridview data with the header of the gridview repeat on each printed page.
I have tried and i have success to repeat the gridview header on each printed page but now it is only printing the gridview Data. I hae to repeat the Page heading also on the each printed page
how do i achieve this
the code i am using is
gvDD.UseAccessibleHeader =
True
gvDD.HeaderRow.TableSection = TableRowSection.TableHeader
gvDD.FooterRow.TableSection = TableRowSection.TableFooter
gvDD.Attributes(
"style") = "border-collapse:separate"
For Each row As GridViewRow In gvDD.Rows
If row.RowIndex Mod 10 = 0 AndAlso row.RowIndex <> 0 Then
row.Attributes(
"style") = "page-break-after:always;"
End If
Next
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
gvDD.RenderControl(hw)
Dim gridHTML As String = sw.ToString().Replace("""", "'").Replace(System.Environment.NewLine, "")
Dim sb As 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(""")
Dim style As String = "<style type = 'text/css'>#content {font-size:1em;} 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(
Me.[GetType](), "GridPrint", sb.ToString())
gvDD.DataBind()
please help
Tuesday, April 9, 2013 1:13 AM
Answers
-
User44562928 posted
Use below sample code,
Add below code in your header section of page
<head runat="server"> <style> @media print { input { display: none; } } </style> </head>
And add below code after bind data to Gridview
GridView1.UseAccessibleHeader = true; GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
Add below sample code on GridView1_RowDataBound event.
if (e.Row.RowType == DataControlRowType.DataRow) { tempcounter = tempcounter + 1 ; if (tempcounter == 10) { e.Row.Attributes.Add("style", "page-break-after: always;"); tempcounter = 0; } }
here I have used tempcounter for set no. of records per page you can change this as per your req.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 9, 2013 2:44 AM
All replies
-
User44562928 posted
Use below sample code,
Add below code in your header section of page
<head runat="server"> <style> @media print { input { display: none; } } </style> </head>
And add below code after bind data to Gridview
GridView1.UseAccessibleHeader = true; GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
Add below sample code on GridView1_RowDataBound event.
if (e.Row.RowType == DataControlRowType.DataRow) { tempcounter = tempcounter + 1 ; if (tempcounter == 10) { e.Row.Attributes.Add("style", "page-break-after: always;"); tempcounter = 0; } }
here I have used tempcounter for set no. of records per page you can change this as per your req.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 9, 2013 2:44 AM -
User-1746098369 posted
Excellent Sample & Explanation ..Thanks it worked
Tuesday, April 9, 2013 3:18 AM