0

除非我在传递组合列表参数时单击查看报告按钮,否则不会加载报告查看器上的图表。

只有在报告查看器上单击“查看报告”按钮后,才能正确传递所有选定的参数并加载报告。我在 ASP.NET 页面上有这个报告查看器,我的参数是使用从另一个 ASP.NET 页面创建的会话变量传递的,该页面具有我的参数表单,用户可以从该页面输入和选择输入参数。

我有日期(日期选择器)和公司名称(带有复选框的多选组合列表)作为输入参数。

除非报告参数来自多选组合列表,否则报告工作绝对正常。

这是我用于将报告参数建立为会话变量的代码。

Session("labname") = Nothing
    Session("fractionid") = FractionDropDownList.SelectedValue
    For intloopindex As Integer = 0 To LabNamesCheckBoxList.Items.Count - 1
        If LabNamesCheckBoxList.Items(intloopindex).Selected Then
            Session("labname") &= LabNamesCheckBoxList.Items(intloopindex).Text & ControlChars.CrLf
        End If
    Next
    Session("sdate") = sdate.text
    Session("edate") = edate.text

这是我将这些会话变量作为参数传递给reportviewer 控件的代码。

If Not IsPostBack Then

        Dim fractionparam As String
        Dim sdateparam As String
        Dim edateparam As String
        Dim regionparam As String
        Dim labnameparam As String

        regionparam = Session("regionid")
        fractionparam = Session("fractionid")
        labnameparam = Session("labname")
        sdateparam = Session("sdate")
        edateparam = Session("edate")


        Dim rp(3) As Microsoft.Reporting.WebForms.ReportParameter

        'rp(0) = New Microsoft.Reporting.WebForms.ReportParameter("regionid", regionparam)
        rp(0) = New Microsoft.Reporting.WebForms.ReportParameter("fractionid", fractionparam)
        rp(1) = New Microsoft.Reporting.WebForms.ReportParameter("labname", labnameparam)
        rp(2) = New Microsoft.Reporting.WebForms.ReportParameter("sdate", sdateparam)
        rp(3) = New Microsoft.Reporting.WebForms.ReportParameter("edate", edateparam)

        Me.ReportViewer1.ServerReport.SetParameters(rp)

    End If
4

1 回答 1

0

我终于得到了解决方案。

我的旧代码犯了一个重大错误。使用多值参数,我试图将组合框列表中的所有选定值作为一个字符串发送。

但我应该使用字符串数组来存储多值参数并使用会话变量发送它们。

包括下面的代码。

dim count as integer
For intloopindex As Integer = 0 To LabNamesCheckBoxList.Items.Count - 1
        If LabNamesCheckBoxList.Items(intloopindex).Selected Then
          count=count+1
        End If    
dim labnames(count) as array

dim j as integer
j=0

for i as integer=0 to labnamescheckboxlist.items.count-1
labnames(j)=labnamescheckboxlist.item(i).text
j=j+1
next

    Session("labname") = Nothing
    Session("labname")=labnames

    Session("fractionid") = FractionDropDownList.SelectedValue
    Session("sdate") = sdate.text
    Session("edate") = edate.text

在目标页面中,读取将所有会话变量作为参数传递,如前面的代码所示。

于 2009-07-18T05:11:20.170 回答