Handling Events
Handling events for elements defined within a DPLX file is done in the following manner. First one must define a report element for which the event will be called (see Accessing Report Elements for more on this). Next, associate a new EventHandler with the event using the += operator. Make sure here that the name provided in the EventHandler constructor exactly matches the name in the signature for the target method. For more information on using a DPLX file see Using a DPLX file or see Using a DPLX file from a Web Form for more on associating a DPLX file with a Web Form.
The following code example demonstrates how to specify and code an event handler for the LaidOut event in order to dynamically place a Barcode in a PlaceHolder:
public void ReportExample()
{
DocumentLayout reportDocument = new DocumentLayout("Filepath/design.dplx");
PlaceHolder barcodePlaceHolder = (PlaceHolder)reportDocument.GetReportElementById( "BarcodePlaceholder" );
barcodePlaceHolder.LaidOut += new PlaceHolderLaidOutEventHandler( BarcodePlaceHolder_LaidOut );
Document document = reportDocument.Run();
document.Draw( @"C:\\Temp\\report.pdf" );
}
public void BarcodePlaceHolder_LaidOut( object sender, PlaceHolderLaidOutEventArgs e )
{
Code128 barcode = new Code128( e.LayoutWriter.RecordSets.Current["OrderID"].ToString(), 0, 0, e.ContentArea.Height );
barcode.X += ( e.ContentArea.Width - barcode.GetSymbolWidth() ) / 2;
barcode.ShowText = false;
e.ContentArea.Add( barcode );
}
Sub ReportExample ()
Dim Report As DocumentLayout = New DocumentLayout("Filepath/design.dplx")
Dim MyBarcodePlaceHolder As PlaceHolder = Report.GetReportElementById("BarcodePlaceholder")
AddHandler MyBarcodePlaceHolder.LaidOut, AddressOf BarcodePlaceholder_LaidOut
Dim MyDocument As Document = Report.Run()
MyDocument.Draw("C:\\Temp\\report.pdf")
End Sub
Private Sub BarcodePlaceholder_LaidOut(ByVal sender As Object, ByVal e As PlaceHolderLaidOutEventArgs)
Dim MyBarcode As Code128 = New Code128(e.LayoutWriter.RecordSets.Current("OrderID").ToString(), 0, 0, e.ContentArea.Height)
MyBarcode.X += (e.ContentArea.Width - MyBarcode.GetSymbolWidth()) / 2
MyBarcode.ShowText = False
e.ContentArea.Add(MyBarcode)
End Sub