问题
I have a Report Viewer Control in my Web page which is responsible to show all the reports.
I want to get the parameters of the report and check if the parameter has allow null property true then I want to pass the parameter value to null.
For this I have tried below code but I am getting AllowBlank property as false for all the parameters:
ReportParameterInfoCollection defaultParams;
List<ReportParameter> reportParams = new List<ReportParameter>();
defaultParams = ReportViewer1.ServerReport.GetParameters();
if (defaultParams.Count > 0)
{
foreach (ReportParameterInfo rp in defaultParams)
{
if (rp.AllowBlank)
{
string str = null;
reportParams.Add(new ReportParameter(rp.Name, str));
}
}
}
回答1:
I have resolved my problem.
Instead of checking the AllowBlank property I have now checked Nullable property.
AllowBlank property is only for string parameters which allows Blank but if you want to check if the parameter allows null value then you have to check the NULLABLE property
New code is as follows:
ReportParameterInfoCollection defaultParams;
List<ReportParameter> reportParams = new List<ReportParameter>();
defaultParams = ReportViewer1.ServerReport.GetParameters();
if (defaultParams.Count > 0)
{
foreach (ReportParameterInfo rp in defaultParams)
{
if (rp.Nullable)
{
string str = null;
reportParams.Add(new ReportParameter(rp.Name, str));
}
}
}
来源:https://stackoverflow.com/questions/22625842/report-viewer-set-null-value-to-report-parameters-having-allow-null-true