Is there any way to pass the dataformat dynamically?
I need to pass in the correct currency type to the dataformat attribute.
ie: £#,##0.00 or $#,##0.00
Dynamically Changing DataFormat
Re: Dynamically Changing DataFormat
Support · Nov 14, 2007Hello,
Yes, you can set the format for the RecordBox using the DataFormat property dynamically. You can also set this in the designer using this property. Following is the sample line of code to set this dynamically.
RecordBox recordBox = (RecordBox)report1.GetElementById("TotalRecordBox");
recordBox.DataFormat = "$#,##0.00";
Thanks,
ceTe Software Support Team.
Re: Dynamically Changing DataFormat
Forum member · Nov 14, 2007Thanks for your quick response.
I had to port it over to vb and here's what i got.
Dim layout As DocumentLayout = New DocumentLayout(MapPath("docoutput.aspx.dplx"))
Dim report1 As Report = layout.GetElementById("Report1")
Dim recordBox As RecordBox = CType(report1.GetElementById("RecordBox8"), RecordBox)
recordBox.DataFormat = "$#,##0.00"
I can't locate the method "GetElementById" after "report1".
Any help would be greatly appreciated.
Re: Dynamically Changing DataFormat
Support · Nov 14, 2007Hello,
Can you please sure that you have the Import statement to use the RecordBox class. If not add the Import statement for the "ceTe.DynamicPDF.ReportWriter.ReportElements" namespace and that will likely solve your problem.
Thanks,
ceTe Software Support Team
Re: Dynamically Changing DataFormat
Forum member · Nov 14, 2007I have it set up that way. Here's what I'm importing.
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.ReportWriter
Imports ceTe.DynamicPDF.ReportWriter.Data
Imports ceTe.DynamicPDF.ReportWriter.ReportElements
Re: Dynamically Changing DataFormat
Support · Nov 14, 2007Hello,
Try the following line of code and that will work for you. The method to use is GetReportElementById and not GetElementById.
Dim MyRecordBox As RecordBox = CType(report1.GetReportElementById ("RecordBox8"), RecordBox)
Thanks,
ceTe Software Support Team
Re: Dynamically Changing DataFormat
Forum member · Nov 14, 2007no luck. Here's the error i get:
'GetReportElementById' is not a member of 'ceTe.DynamicPDF.ReportWriter.Report'.
For review here's what im using for code:
Imports System
Imports System.IO
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.ReportWriter
Imports ceTe.DynamicPDF.ReportWriter.Data
Imports ceTe.DynamicPDF.ReportWriter.ReportElements
Partial Class docoutput
Inherits DplxWebForm
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim layout As DocumentLayout = New DocumentLayout(MapPath("docoutput.aspx.dplx"))
Dim report1 As ReportWriter.Report = layout.GetElementById("Report1")
Dim MyRecordBox As RecordBox = CType(report1.GetReportElementById("RecordBox8"), RecordBox)
MyRecordBox.DataFormat = "$#,##0.00"
DrawPdf("output.pdf")
End Sub
Re: Dynamically Changing DataFormat
Support · Nov 14, 2007Hello,
Can you please try the following code and it will likely solve your problem:
Dim layout As DocumentLayout = New DocumentLayout("Test.aspx.dplx")
Dim MyRecordBox As RecordBox = CType(layout.GetReportElementById("RecordBox8"), RecordBox)
MyRecordBox.DataFormat = "$#,##0.00"
DrawPdf("output.pdf")
Thanks,
ceTe Software Support Team
Re: Dynamically Changing DataFormat
Forum member · Nov 14, 2007Doesn't appear to be targeting the recordbox.
I even tried creating a test using the northwindDB. The code i used is below.
------testit.aspx---------------------
Imports System
Imports System.IO
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.ReportWriter
Imports ceTe.DynamicPDF.ReportWriter.Data
Imports ceTe.DynamicPDF.ReportWriter.ReportElements
Partial Class testit
Inherits DplxWebForm
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim layout As DocumentLayout = New DocumentLayout(MapPath("testit.aspx.dplx"))
Dim report1 As Report = layout.GetElementById("Report1")
Dim MyRecordBox As RecordBox = CType(layout.GetReportElementById("RecordBox2"), RecordBox)
MyRecordBox.DataFormat = "$#,##0.00"
Dim vpath As String = Server.MapPath("test.pdf")
DrawPdf(vpath)
End Sub
End Class
-------testit.aspx.dplx------------------
<?xml version="1.0"?>
<document xsi:schemaLocation="http://www.DynamicPDF.com http://www.DynamicPDF.com/schemas/DPLX4.xsd" version="4.0" id="Document" author="" keywords="" title="" subject="" xmlns="http://www.DynamicPDF.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<report id="Report1">
<query id="Query" dataProvider="msSql" connectionString="Data Source=localhost;Initial Catalog=northwind;Persist Security Info=True;User ID=test;Password=test">
<sql>select * from [order details] where orderid = 10248</sql>
</query>
<header id="Header" height="50"/>
<body id="Body" height="19.5">
<recordBox id="RecordBox1" dataFormat="" height="14" width="100" x="102" y="1.5" field="orderid"/>
<recordBox dataFormat="" height="14" width="100" y="1.5" id="RecordBox2" x="204.5" field="UnitPrice"/>
</body>
<footer id="Footer" height="50"/>
</report>
</document>
Re: Dynamically Changing DataFormat
Forum member · Nov 14, 2007I was trying to troubleshoot and forgot to remove a line. But it's
still not formating.
Again, Here is what i used.
----testit.aspx.vb-----------------------------------------------------------------------------
Imports System
Imports System.IO
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.ReportWriter
Imports ceTe.DynamicPDF.ReportWriter.Data
Imports ceTe.DynamicPDF.ReportWriter.ReportElements
Partial Class testit
Inherits DplxWebForm
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim layout As DocumentLayout = New DocumentLayout(MapPath("testit.aspx.dplx"))
Dim MyRecordBox As RecordBox = CType(layout.GetReportElementById("RecordBox2"), RecordBox)
MyRecordBox.DataFormat = "$#,##0.00"
Dim vpath As String = Server.MapPath("test.pdf")
DrawPdf(vpath)
End Sub
End Class
-----testit.aspx.dplx----------------------------------------------------------------------------
<?xml version="1.0"?>
<document xsi:schemaLocation="http://www.DynamicPDF.com http://www.DynamicPDF.com/schemas/DPLX4.xsd" version="4.0" id="Document" author="" keywords="" title="" subject="" xmlns="http://www.DynamicPDF.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<report id="Report1">
<query id="Query" dataProvider="msSql" connectionString="Data Source=localhost;Initial Catalog=northwind;Persist Security Info=True;User ID=test;Password=test">
<sql>select * from [order details] where orderid = 10248</sql>
</query>
<header id="Header" height="50"/>
<body id="Body" height="19.5">
<recordBox id="RecordBox1" dataFormat="" height="14" width="100" x="102" y="1.5" field="orderid"/>
<recordBox dataFormat="" height="14" width="100" y="1.5" id="RecordBox2" x="204.5" field="UnitPrice"/>
</body>
<footer id="Footer" height="50"/>
</report>
</document>
-----output----------------------------------------------------------------------------------
OrderID UnitPrice
10248 14.0000
10248 9.8000
10248 34.8000
Re: Dynamically Changing DataFormat
Support · Nov 15, 2007Hello,
Actually there was a misunderstanding from the beginning of this forum which is causing this behavior. In our first reply at 10:57 AM, the "report1" is an object of the DocumentLayout class and you are creating a Report object and trying to access the GetElementById method which is available from the DocumentLayout object and not from the Report object. Sorry for causing this confusion.
One more thing to notice here is you are using a DplxWebForm and its method DrawPdf to draw the PDF. In this scenario you will have to use the "Me" keyword which represents the current DplxWebForm to access the current DocumentLayout and its elements. But you are creating a new DocumentLayout object and changing the properties for the element and you are drawing the PDF from another instance of the DocumentLayout which is from the DplxWebForm. Following are the sample codes to use in the DplxWebForm and to use in ordinary webpages.
Using the DplxWebForm:
Partial Class ReportWriterExamples_Invoice
Inherits DplxWebForm
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'The dplx we used here requires a Parameter. You can remove this if your dplx does not require.
Parameters.Add("OrderID", "10248")
'Create a RecordBox from the document layout
Dim recordBox As RecordBox = CType(Me.DocumentLayout.GetElementById("TotalRecordBox"), RecordBox)
'Change the property
recordBox.DataFormat = "$#,##0.00"
'Draw the pdf to page or save it
DrawPdfToWeb()
End Sub
End Class
Using the Ordinary WebPage and a dplx file:
Partial Class ReportWriterExamples_Invoice
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create the DocumentLayout object
Dim report1 As New DocumentLayout("C:\Temp\Invoice.aspx.dplx")
'This dplx requires a parameter
Dim params As New ParameterDictionary()
params.Add("OrderID", "10248")
'get the RecordBox object from the document leyout
Dim recordBox As RecordBox = CType(report1.GetElementById("TotalRecordBox"), RecordBox)
'Change the property
recordBox.DataFormat = "$#,##0.00"
'Create a document using this document layout
Dim document As Document = report1.Run(params)
'Draw this pdf to the webpage or save it
document.DrawToWeb()
End Sub
End Class
Thanks,
ceTe Software Support Team.