此代码将循环遍历一组参数并将它们添加到报表查看器。您应该制定一种getParameterName(int)
方法来获取 rv 的名称。
int[] parameters = new int[1];
parameters[0] = 10;
//Create Parameter Collection Array
Microsoft.Reporting.WebForms.ReportParameter[] reportParameterCollection = new Microsoft.Reporting.WebForms.ReportParameter[parameters.Length];
//Loop through each parameter and load the name and value into the parameter collection
int i = 0;
foreach (int parameter in parameters)
{
reportParameterCollection[i] = new Microsoft.Reporting.WebForms.ReportParameter();
reportParameterCollection[i].Name = getParameterName(i);
reportParameterCollection[i].Values.Add((parameters[i]);
i++;
}
//Load Parameters into the ReportViewer
ReportViewer1.ServerReport.SetParameters(reportParameterCollection);
ReportViewer1.ServerReport.Refresh();
我自己更像是一个 C# 人,但这是我在 5 秒后在 vb.net 上的手:
Dim paramList As New Generic.List(Of ReportParameter)
paramList.Add(New ReportParameter("Report_Parameter1","")
Me.ReportViewer1.LocalReport.SetParameters(paramList)
ReportViewer1.RefreshReport()