我被上述错误所困扰。
我有一个名为 loc 的参数的报告。
该报告的预期目的是允许用户从下拉列表中选择一个位置,然后将与该位置关联的记录显示给用户。
下拉列表中的值填充得很好。
但是,当我从下拉列表中选择一个位置时,我收到一条错误消息:
值不能为空。参数名称:reportParameters
当我将值作为文本框而不是下拉列表传递时,一切正常。
任何想法我做错了什么?
以下是相关代码。请原谅我提前发布大量代码。
'---Dropdownlist control
<asp:Panel runat="server" ID="pnlLoc" Font-Names="Calibri" BorderStyle="Solid" BorderWidth="1" Style="margin: 0 auto; width:300px;">
<table>
<tr>
<td>
<asp:Label runat="server" ID="lblLoc" Text="Location: " />
</td>
<td>
<asp:DropDownList runat="server" ID="ddLoc" DataSourceID="dslocator6" AutoPostBack="True">
</asp:DropDownList>
</td>
</tr>
</table>
</asp:Panel
--Report viewer control
<rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="true" SizeToReportContent="true" Font-Names="Arial"
Height="675px" Width="750px">
<LocalReport EnableExternalImages="true" ReportPath="">
</LocalReport>
</rsweb:ReportViewer></center>
<asp:ObjectDataSource ID="LOC" runat="server" SelectMethod="GetData" TypeName="ManageReportsTableAdapters.searchBylocationsTableAdapter">
<SelectParameters>
<asp:ControlParameter ControlID="ddLoc" Name="Location" DefaultValue=" " />
</SelectParameters>
</asp:ObjectDataSource>
--This code populates the ddLoc dropdownlist
Protected Sub btnLoc_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLoc.Click
ReportViewer1.LocalReport.ReportPath = ""
pnlLoc.Visible = True
which.Value = "P"
dslocator6.SelectCommand = "SELECT location FROM Locations ORDER BY [location]"
ddLoc.DataTextField = "location"
ddLoc.DataValueField = "location"
End Sub
'Define report parameter
Dim params(0) As ReportParameter
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("locs", LOC.ID))
ReportViewer1.LocalReport.ReportPath = "locations.rdlc"
ReportViewer1.LocalReport.Refresh()
If Not String.IsNullOrEmpty(ddLoc.SelectedValue) Then
params(0) = New ReportParameter("loc", ddLoc.SelectedValue)
Else
params(0) = New ReportParameter("loc", sel, False)
End If
ReportViewer1.LocalReport.SetParameters(params) '<-- error points to this line