报表查看器:将“空值"设置为“允许空值"的“报表参数" [英] Report Viewer: Set null value to Report Parameters having allow null true

查看:141
本文介绍了报表查看器:将“空值"设置为“允许空值"的“报表参数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个Report Viewer控件,它负责显示所有报告.

I have a Report Viewer Control in my Web page which is responsible to show all the reports.

我想获取报表的参数,并检查该参数是否具有allow null属性为true,然后将参数值传递给null.

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.

为此,我尝试了以下代码,但对于所有参数,我都将AllowBlank属性设置为false:

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));
         }
     }
}

推荐答案

我已经解决了我的问题.

I have resolved my problem.

我现在没有检查AllowBlank属性,而是检查了Nullable属性.

Instead of checking the AllowBlank property I have now checked Nullable property.

AllowBlank属性仅适用于允许空白的字符串参数,但是如果您要检查参数是否允许空值,则必须检查NULLABLE属性

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

新代码如下:

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));
         }
     }
}

这篇关于报表查看器:将“空值"设置为“允许空值"的“报表参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆