Print Page | Close Window

Passing multi select parameters in asp.net

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Writing Code
Forum Discription: .NET 2003 programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=3309
Printed Date: 04 May 2024 at 5:25pm


Topic: Passing multi select parameters in asp.net
Posted By: yasinirshad
Subject: Passing multi select parameters in asp.net
Date Posted: 31 May 2008 at 3:46am
Hi,
how to pass multi select paramteres in asp.net..
 I will have 3 Paramters i.e., on my webform user will select
*. startdate and enddate
*. Division
*. Department
If user had selected one division (ex: Fin) and one department(ex: Finance) then i would not have any problem.
But here user can select multiple division (ex: Fin,IT,HR) and multiple departments (ex: Finance,Information.Tech,Human Resources) then how to pass this multiple paramters in asp.net?
I have sample code which i used in previous project for passing single parameters..below is code,
Below am passing Date (Period), ProjectNo and SupplierCode (Here user can select only one Project No and SupplierCode).
Try
            If ConState = False Then
                Connect()
            End If
            Dim ConnInfo As New ConnectionInfo
            With ConnInfo
                .ServerName = mOleDB.strServerName
                .DatabaseName = mOleDB.strDBName
                .UserID = mOleDB.strUsrName
                .Password = mOleDB.strUsrPwd
            End With
            ' Declare variables needed to pass the parameters
            ' to the viewer control.
            Dim paramFields As New ParameterFields
            Dim paramField As New ParameterField
            Dim discreteVal As New ParameterDiscreteValue
            Dim rangeVal As New ParameterRangeValue
            ' Set the name of the parameter field, this must match a
            ' parameter in the report. (Date Parameter)
            paramField.ParameterFieldName = "Period"
            ' Set the start and end values of the range and pass it to the 'parameter.
            rangeVal.StartValue = ClosedReport.StartDate
            rangeVal.EndValue = ClosedReport.EndDate
            paramField.CurrentValues.Add(rangeVal)
            ' Add the first parameter to the parameter fields collection.
            paramFields.Add(paramField)
            ' The second parameter is a discrete value. The paramField variable
            ' is set to new so the previous settings will not be overwritten.
            paramField = New ParameterField
            'Set the name of the parameter field, this must match a
            ' parameter in the report.
            paramField.ParameterFieldName = "ProjectNo"
            ' Set the first discrete value and pass it to the parameter based on conditions.
            If ClosedReport.ProjectNo <> "" Then
                discreteVal.Value = ClosedReport.ProjectNo
            Else
                discreteVal.Value = "*"
            End If
            paramField.CurrentValues.Add(discreteVal)
            ' Add the parameter to the parameter fields collection.
            paramFields.Add(paramField)
            ' Set the second discrete value and pass it to the parameter.
            ' The discreteVal variable is set to new so the previous settings
            ' will not be overwritten.
            paramField = New ParameterField
            'Set the name of the parameter field, this must match a
            ' parameter in the report.
            paramField.ParameterFieldName = "SupplierCode"
            discreteVal = New ParameterDiscreteValue
            ' Set the second discrete value and pass it to the parameter based on conditions.
            If ClosedReport.SupplierCode <> "" Then
                discreteVal.Value = ClosedReport.SupplierCode
            Else
                discreteVal.Value = "*"
            End If
            paramField.CurrentValues.Add(discreteVal)
            ' Add the parameter to the parameter fields collection.
            paramFields.Add(paramField)
            ' Set the parameter fields collection into the viewer control.
            CrystalReportViewer_SuppProjOpen.ParameterFieldInfo = paramFields
            CrystalReportViewer_SuppProjOpen.ReportSource = crReportDocument
            For Each cnInfo As TableLogOnInfo In Me.CrystalReportViewer_SuppProjOpen.LogOnInfo
                cnInfo.ConnectionInfo = ConnInfo
            Next
            'Me.CrystalReportViewer_SuppProjClosed.RefreshReport()
            CrystalReportViewer_SuppProjOpen.Visible = True
        Catch err As System.Exception
            MessageBox.Show(err.Message, "System error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
 
Thanks to help.


-------------
Thanks,
Yasin.



Replies:
Posted By: BrianBischof
Date Posted: 31 May 2008 at 8:19pm
Unfortuanately, CR doesn't let you pass multi-value parameters to a report. You can only pass discrete values or range values. One option is to pass a comma delimited string to CR and then use the Split() function to convert the string to a CR array variable.

I have extensive coverage of arrays and a reference of array functions in my Encyclopedia book. You can find out more about my books at http://www.amazon.com/exec/obidos/ASIN/0974953601/bischofsystem-20 - Amazon.com or reading the http://members.crystalreportsbook.com - Crystal Reports eBooks online.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: yasinirshad
Date Posted: 01 Jun 2008 at 4:47am
 
Hi,
You said
 "One option is to pass a comma delimited string to CR and then use the Split() function to convert the string to a CR array variable. "
 
Do You mean..If i have a discrete Parameter "Division" whose values are "BD,IT,HR" then i shd do as below...
 
           Dim array As String() = {"BD", "IT", "HR"}
         Dim strSplit() As String = array.Split(",")
 
            ' The parameter is a discrete value. The paramField variable
            ' is set to new so the previous settings will not be overwritten.
            paramField = New ParameterField
            'Set the name of the parameter field, this must match a
            ' parameter in the report.
            paramField.ParameterFieldName = "Division"
            ' Set the first discrete value and pass it to the parameter 
            discreteVal.Value = frmNCNClosedReport.ProjectNo
           paramField.CurrentValues.Add(discreteVal)
 
And then can u help me pls how to proceed..
Here my Discrete Parameter name is "Division"
 
Pls help.
 
Can you please explain me in little more detail how to do this..
Thanks to help with Code.
Thanks.


-------------
Thanks,
Yasin.



Print Page | Close Window