Report Viewer: Set null value to Report Parameters having allow null true

爱⌒轻易说出口 提交于 2019-12-13 01:25:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!