Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

paging in datagrid

Status
Not open for further replies.

bigmelon

MIS
Sep 25, 2003
114
US
i have a datagrid that displays, then have a printer friendly mode so that is all fits within the width of the page. when you get to this page, i have the printer dialog box popup immediately so u can print right away. however, it often spans multiple pages and the last record is half on one page and half on the next. so i enable paging, but then you can only print the current page not the whole datagrid. is there a way to get all pages (mostly only 2 or 3) to print initially, or a different way to force a page break so that the data is not displayed partially over 2 pages?

thanks in advance

big
 
I have had this same problem!
What I did was use some Inline Cascading styles and some good old looping code.

the HTMl For the page is
---------------------------------------------------------
<html>
<head>
<title>PrintStoreSupInfo</title>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft Visual Studio .NET 7.1&quot;>
<meta name=&quot;CODE_LANGUAGE&quot; content=&quot;Visual Basic .NET 7.1&quot;>
<meta name=vs_defaultClientScript content=&quot;JavaScript&quot;>
<meta name=vs_targetSchema content=&quot; <STYLE TYPE=&quot;text/css&quot;>
P.breakhere { PAGE-BREAK-BEFORE: always }

</STYLE>
</head>
<body MS_POSITIONING=&quot;GridLayout&quot;>

<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;>

</form>

</body>
</html>
----------------------------------------------------
'The important part is in the Style tags it will allow you to break the page when you want to.

the hard part is in the codebehind. here I actualy output the table using Response.write() I loop through the dataset, check to make sure what row I am on, and if I need to start a new page I start a new table, but I also start a new paragraph using the pagebreak style. here is the code behind, hope its easy to figure out

-----------------------------------------------------------
Inherits System.Web.UI.Page

#Region &quot;Page Variables&quot;
Dim oDs As Data.DataSet
Dim tpapp As TPPhoneService.TiresplusWebService = New TPPhoneService.TiresplusWebService
#End Region


#Region &quot; Web Form Designer Generated Code &quot;

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim ssql As String
ssql = &quot;Select Rtrim(heading), Rtrim(SubHead), Isnull(Rtrim(Person),''), isnull(Rtrim(PhNumber),'') From StoreSupportInfo order by heading, sequence, subhead&quot;

oDs = tpapp.GenericDataset(ssql)

PrintPageHeader()
PrintReport()


End Sub
Sub PrintPageHeader()
Response.Write(&quot;<p align='center'><b><Font Name='Verdana' size='5'>Store Support Center Info</font><br> &quot;)
Response.Write(&quot;<font name='Verdana' size='2'>&quot; & Now.ToShortDateString & &quot;</font></b><br>&quot;)
End Sub
Sub PrintReport()
Dim x As Integer
Dim iRows As Integer = 35 ' number of rows per page
Dim iCounter As Integer = iRows 'start the counter at 40 so the first page wont get a break
Dim gotdata As Boolean

Dim strCurrentState As String = &quot;&quot;



If oDs.Tables(0).Rows.Count > 0 Then
Dim drDataRow As Data.DataRow
Dim strHeading As String = &quot;&quot;
'If oDr.HasRows Then 'check if the reader has data

'ok we have some data we can create the first row
gotdata = True
For Each drDataRow In oDs.Tables(0).Rows

'Do While gotdata
If iCounter Mod iRows = 0 Then
If iCounter = iRows Then ' just to make sure that the page doesnt break on the first page
Response.Write(&quot;<Table width='100%' BORDER='1' RULES='cols'><Font size='2'>&quot;) 'Create the Table
Else
Response.Write(&quot;<p class='breakhere'>&quot;) ' here is the magic
'the previous line will cause the page to break and start a new page
Response.Write(&quot;<h2>Store Support Center Info cont.</h2><Table BORDER='1' RULES='cols' width='100%'><Font size='2'>&quot;) 'Create the Table
End If

Response.Write(&quot;<tr>&quot;)

Else
Response.Write(&quot;<tr>&quot;)
End If
iCounter += 1
' Supress the 0 in Extension
If drDataRow.ItemArray(0).ToString <> strHeading Then
Response.Write(&quot;<td Align='center'><font size='4'><u>&quot; & StrConv(drDataRow.ItemArray(0).ToString, VbStrConv.ProperCase) & &quot;</u></font></td><td><hr></td><td><hr></td></tr><tr>&quot;) ' Extension
strHeading = drDataRow.ItemArray(0).ToString
End If

Response.Write(&quot;<td align='left'><font name='Verdana' size='2'>&quot; & drDataRow.ItemArray(1) & &quot;</font></td>&quot;) ' Name
Response.Write(&quot;<td align='left'><font name='Verdana' size='2'>&quot; & drDataRow.ItemArray(2) & &quot;</font></td>&quot;) ' Department
Response.Write(&quot;<td align='left'><font name='Verdana' size='2'>&quot; & drDataRow.ItemArray(3) & &quot;</font></td>&quot;) ' Voice Mail



Response.Write(&quot;</tr>&quot;)
If iCounter Mod iRows = 0 Then
Response.Write(&quot;</font></Table></P>&quot;)
End If
Next

End If
End Sub
----------------------------------------------------------

Hope this helps :)

George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
Check out this awsome .Net Resource!
 
would it be possible to force a break while still using a datagrid?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top