To allow passing a procedure parameter to an XtraReport descendant class (XtraReport1), it's updated with an argument which is used while populating the DataSet instance.
On the web page, a DropDownList control is placed, which is populated with the list of parameters.
In the example, the "CustOrdersOrders" stored procedure (Northwind database) with the "CustomerID" parameter is used, so the DropDownList contains every CustomerID from the Customers table.
Within the Page_Load event handler, the ReportViewer.Report property is updated using a newly created report instance.
Question Comments
Added By:
Jay Johnson at:
6/14/2012 2:26:38 PM Is there any "How To" for this? It seems to contradict other examples which use _BeforePrint
Is part of this example missing?
Added By:
Mark D Loaney at:
6/20/2012 3:59:08 AM I've been wasting days trying to get this working, it appears that when I pass the parameters in the system breaks. I have a procedure that has the following parameters:
@OrganisationID INT = 0,
@Key INT = 3,
@WeekStarting DATE = NULL,
@WeekEnding DATE = NULL,
@DivisionID INT = 0,
@WorkgroupID INT = 0,
@EmployeeID INT = 281,
@Factor FLOAT = 0.00000
of which I only really need Key, EmployeeID, Division and Workgroup
The 'New' in xtrareports is as follows (note if I comment out the parameters passed in it works with the detault values and returns data:
Public Sub New(ByVal mEmployeeID As Integer, ByVal mKey As Integer, ByVal Org As Integer, divsn As Integer, wrkgp As Integer)
MyBase.New()
'This call is required by the Designer.
InitializeComponent()
cpM_Reports_StaffTableAdapter1.Fill(Me.staff1.CPM_Reports_Staff, Convert.ToInt32(Org), Convert.ToInt32(mKey), Convert.ToDateTime(Now()), Convert.ToDateTime(Now()), Convert.ToInt32(divsn), Convert.ToInt32(wrkgp), Convert.ToInt32(mEmployeeID))
End Sub
ie this works, but of course the parameters aren't there!
Public Sub New() 'ByVal mEmployeeID As Integer, ByVal mKey As Integer, ByVal Org As Integer, divsn As Integer, wrkgp As Integer)
MyBase.New()
'This call is required by the Designer.
InitializeComponent()
'cpM_Reports_StaffTableAdapter1.Fill(Me.staff1.CPM_Reports_Staff, Convert.ToInt32(Org), Convert.ToInt32(mKey), Convert.ToDateTime(Now()), Convert.ToDateTime(Now()), Convert.ToInt32(divsn), Convert.ToInt32(wrkgp), Convert.ToInt32(mEmployeeID))
End Sub
The proper values are coming in to the system when I put in a breakpoint - seems that the initialise isn't firing??
The code on the webform is
Dim Division As Integer = 0
Dim Workgroup As Integer = 0
Dim Key As Integer = lstFilter.SelectedIndex
If IsNumeric(lstDivision.SelectedValue) Then Division = CInt(lstDivision.SelectedValue)
If IsNumeric(lstWorkgroup.SelectedValue) Then Workgroup = lstWorkgroup.SelectedValue
Dim report As New XStaffActivity(Helpers.EmployeeID, Key, Helpers.MyCompanyID, Division, Workgroup)
rvStaffActivity.Report = report
Help please (PS I've copied the full xtrareports code below (cutting out the 60 off labels etc on there):
Imports System
Imports DevExpress.XtraReports.UI
Imports System.Drawing.Printing
Public Class XStaffActivity
Inherits DevExpress.XtraReports.UI.XtraReport
#Region " Designer generated code "
Public Sub New(ByVal mEmployeeID As Integer, ByVal mKey As Integer, ByVal Org As Integer, divsn As Integer, wrkgp As Integer)
MyBase.New()
'This call is required by the Designer.
InitializeComponent()
cpM_Reports_StaffTableAdapter1.Fill(Me.staff1.CPM_Reports_Staff, Convert.ToInt32(Org), Convert.ToInt32(mKey), _
Convert.ToDateTime(Now()), Convert.ToDateTime(Now()), Convert.ToInt32(divsn), _
Convert.ToInt32(wrkgp), Convert.ToInt32(mEmployeeID))
End Sub
'XtraReport overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
Private WithEvents staff1 As Staff
Private WithEvents cpM_Reports_StaffTableAdapter1 As StaffTableAdapters.CPM_Reports_StaffTableAdapter
Private WithEvents groupHeaderBand1 As DevExpress.XtraReports.UI.GroupHeaderBand
Private WithEvents xrLabel2 As DevExpress.XtraReports.UI.XRLabel
Private WithEvents groupHeaderBand2 As DevExpress.XtraReports.UI.GroupHeaderBand
Private WithEvents xrLabel4 As DevExpress.XtraReports.UI.XRLabel
Private WithEvents groupHeaderBand3 As DevExpress.XtraReports.UI.GroupHeaderBand Private WithEvents xrPageInfo1 As DevExpress.XtraReports.UI.XRPageInfo
Private WithEvents xrPageInfo2 As DevExpress.XtraReports.UI.XRPageInfo
Private WithEvents reportHeaderBand1 As DevExpress.XtraReports.UI.ReportHeaderBand
Private WithEvents xrLabel23 As DevExpress.XtraReports.UI.XRLabel
Private WithEvents groupFooterBand1 As DevExpress.XtraReports.UI.GroupFooterBand
Private WithEvents groupFooterBand2 As DevExpress.XtraReports.UI.GroupFooterBand
Private WithEvents xrLabel24 As DevExpress.XtraReports.UI.XRLabel
Private WithEvents Title As DevExpress.XtraReports.UI.XRControlStyle
Private WithEvents FieldCaption As DevExpress.XtraReports.UI.XRControlStyle
Private WithEvents PageInfo As DevExpress.XtraReports.UI.XRControlStyle
Private WithEvents DataField As DevExpress.XtraReports.UI.XRControlStyle
Private WithEvents topMarginBand1 As DevExpress.XtraReports.UI.TopMarginBand
Private WithEvents bottomMarginBand1 As DevExpress.XtraReports.UI.BottomMarginBand
'Required by the Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Designer
'It can be modified using the Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim resourceFileName As String = "XStaffActivity.resx"
Dim xrSummary1 As DevExpress.XtraReports.UI.XRSummary = New DevExpress.XtraReports.UI.XRSummary()
Dim xrSummary33 As DevExpress.XtraReports.UI.XRSummary = New DevExpress.XtraReports.UI.XRSummary()
Me.Detail = New DevExpress.XtraReports.UI.DetailBand()
Me.xrLabel60 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrVEmployee = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel51 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel14 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel15 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel16 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel17 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel18 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel19 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel20 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel21 = New DevExpress.XtraReports.UI.XRLabel()
Me.xrLabel22 = New DevExpress.XtraReports.UI.XRLabel()
Me.staff1 = New Staff()
Me.cpM_Reports_StaffTableAdapter1 = New StaffTableAdapters.CPM_Reports_StaffTableAdapter() Me.Title = New DevExpress.XtraReports.UI.XRControlStyle()
Me.FieldCaption = New DevExpress.XtraReports.UI.XRControlStyle()
Me.PageInfo = New DevExpress.XtraReports.UI.XRControlStyle()
Me.DataField = New DevExpress.XtraReports.UI.XRControlStyle()
Me.topMarginBand1 = New DevExpress.XtraReports.UI.TopMarginBand()
Me.bottomMarginBand1 = New DevExpress.XtraReports.UI.BottomMarginBand()
CType(Me.staff1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
'
'Detail
'
Me.Detail.Controls.AddRange(New DevExpress.XtraReports.UI.XRControl() {Me.xrLabel60, Me.xrVEmployee, Me.xrLabel51, Me.xrLabel14, Me.xrLabel15, Me.xrLabel16, Me.xrLabel17, Me.xrLabel18, Me.xrLabel19, Me.xrLabel20, Me.xrLabel21, Me.xrLabel22})
Me.Detail.HeightF = 17.0!
Me.Detail.Name = "Detail"
Me.Detail.Padding = New DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100.0!)
Me.Detail.StyleName = "DataField"
Me.Detail.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft
'
'Title
'
Me.Title.BackColor = System.Drawing.Color.Transparent
Me.Title.BorderColor = System.Drawing.Color.Black
Me.Title.Borders = DevExpress.XtraPrinting.BorderSide.None
Me.Title.BorderWidth = 1
Me.Title.Font = New System.Drawing.Font("Arial Narrow", 21.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Title.ForeColor = System.Drawing.Color.Black
Me.Title.Name = "Title"
'
'FieldCaption
'
Me.FieldCaption.BackColor = System.Drawing.Color.Transparent
Me.FieldCaption.BorderColor = System.Drawing.Color.Black
Me.FieldCaption.Borders = DevExpress.XtraPrinting.BorderSide.None
Me.FieldCaption.BorderWidth = 1
Me.FieldCaption.Font = New System.Drawing.Font("Arial Narrow", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FieldCaption.ForeColor = System.Drawing.Color.Black
Me.FieldCaption.Name = "FieldCaption"
'
'PageInfo
'
Me.PageInfo.BackColor = System.Drawing.Color.Transparent
Me.PageInfo.BorderColor = System.Drawing.Color.Black
Me.PageInfo.Borders = DevExpress.XtraPrinting.BorderSide.None
Me.PageInfo.BorderWidth = 1
Me.PageInfo.Font = New System.Drawing.Font("Arial", 8.0!)
Me.PageInfo.ForeColor = System.Drawing.Color.Black
Me.PageInfo.Name = "PageInfo"
'
'DataField
'
Me.DataField.BackColor = System.Drawing.Color.Transparent
Me.DataField.BorderColor = System.Drawing.Color.Black
Me.DataField.Borders = DevExpress.XtraPrinting.BorderSide.None
Me.DataField.BorderWidth = 1
Me.DataField.Font = New System.Drawing.Font("Arial", 9.0!)
Me.DataField.ForeColor = System.Drawing.Color.Black
Me.DataField.Name = "DataField"
Me.DataField.Padding = New DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100.0!)
'
'topMarginBand1
'
Me.topMarginBand1.HeightF = 31.0!
Me.topMarginBand1.Name = "topMarginBand1"
'
'bottomMarginBand1
'
Me.bottomMarginBand1.HeightF = 25.0!
Me.bottomMarginBand1.Name = "bottomMarginBand1"
'
'XStaffActivity
'
Me.Bands.AddRange(New DevExpress.XtraReports.UI.Band() {Me.Detail, Me.groupHeaderBand1, Me.groupHeaderBand2, Me.groupHeaderBand3, Me.pageFooterBand1, Me.reportHeaderBand1, Me.groupFooterBand2, Me.groupFooterBand3, Me.reportFooterBand1, Me.topMarginBand1, Me.bottomMarginBand1})
Me.DataAdapter = Me.cpM_Reports_StaffTableAdapter1
Me.DataMember = "CPM_Reports_Staff"
Me.DataSource = Me.staff1
Me.Landscape = True
Me.Margins = New System.Drawing.Printing.Margins(83, 55, 31, 25)
Me.PageHeight = 850
Me.PageWidth = 1100
Me.StyleSheet.AddRange(New DevExpress.XtraReports.UI.XRControlStyle() {Me.Title, Me.FieldCaption, Me.PageInfo, Me.DataField})
Me.Version = "12.1"
CType(Me.staff1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
Friend WithEvents Detail As DevExpress.XtraReports.UI.DetailBand
#End Region
End Class
Added By:
Mark D Loaney at:
6/21/2012 2:54:27 AM Never mind, problem solved, I wasn't passing the parameters in on everypost back - had the code in a 'on Not Page.IsPostBack Then ...
took it out of that and beautiful!!
Added By:
Thue Møller Jensen at:
12/7/2012 5:39:38 AM Thansk a lot Mark to Mark for posting this last comment. After wasting a couple of days on this problem, i found this page with the solution.
Added By:
Henry F. Wilson at:
5/7/2014 11:08:50 AM Truly grateful. I have spent days finding solution to this problem and this post solves. Thanks guys.