Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#ASP.NET使用ASP.NET中代码隐藏中的布尔变量_C#_Asp.net_Variables_Boolean - Fatal编程技术网

C#ASP.NET使用ASP.NET中代码隐藏中的布尔变量

C#ASP.NET使用ASP.NET中代码隐藏中的布尔变量,c#,asp.net,variables,boolean,C#,Asp.net,Variables,Boolean,我知道如何从代码到后台使用字符串变量,并在网页上显示该字符串。我想做的是类似的,除了不显示字符串之外,我想将布尔值从code behind传递到ASP.NET页面,以便其“true/false”值可以控制ReportViewer中的打印按钮(true/false)。我的诊断工作原理是,它显示字符串“True”或“False”,这是正确的。“ShowPrintButton”和“ShowExportControls”只是不起作用,而且按钮没有启用。我需要在这里做什么?我认为该值正在被传递,但可能它是

我知道如何从代码到后台使用字符串变量,并在网页上显示该字符串。我想做的是类似的,除了不显示字符串之外,我想将布尔值从code behind传递到ASP.NET页面,以便其“true/false”值可以控制ReportViewer中的打印按钮(true/false)。我的诊断工作原理是,它显示字符串“True”或“False”,这是正确的。“ShowPrintButton”和“ShowExportControls”只是不起作用,而且按钮没有启用。我需要在这里做什么?我认为该值正在被传递,但可能它是作为字符串传递的,我需要做一些事情使其作为布尔值传递

这是密码

代码隐藏:

    //Variables
    public Boolean exportEnabled { get; set; }
    public Boolean printEnabled { get; set; }

    //Page Load
    protected void Page_Load(object sender, EventArgs e)
    {
        // Add a handler for SubreportProcessing
        reportViewerPrintAndExport.LocalReport.SubreportProcessing +=
            new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);

        if (!IsPostBack)
        {
            // Display the report
            DisplayReport(Session[SessionKeys.KEY_CERT_NO].ToString(), (CalibrationType)Session[SessionKeys.KEY_CERT_TYPE]);
        }
        DataBind();
    }

    private void DisplayReport(string certNo, CalibrationType calType)
    {
        string[] rolesList = Roles.GetRolesForUser();

        //manage print and export buttons.
        if ((rolesList.Contains("admin")) || (rolesList.Contains("Admin")))
        {
            exportEnabled = true;
            printEnabled = true;
        }
        else if ((rolesList.Contains("Operator")) || (rolesList.Contains("operator")))
        {
            exportEnabled = false;
            printEnabled = false;
        }
    }
aspx:


在您的代码隐藏中,只需将该属性设置在您想要的任何位置

    if ((rolesList.Contains("admin")) || (rolesList.Contains("Admin")))
    {
        reportViewerPrintAndExport.ShowPrintButton = true;
        reportViewerPrintAndExport.ShowExportControls = true;
    }
    else if ((rolesList.Contains("Operator")) || (rolesList.Contains("operator")))
    {
        reportViewerPrintAndExport.ShowPrintButton = false;
        reportViewerPrintAndExport.ShowExportControls = false;
    }

没有必要在客户端尝试这样做。

没有必要在代码中有这么多空白,这只是意味着人们需要做的滚动远远超过代码数量所需要的。而不是做
if((rolesList.Contains(“admin”))|(rolesList.Contains(“admin”)
你可以只做
if(rolesList.Contains(“admin”)
if(rolesList.Contains”)(“Admin”,StringComparer.InvariantCultureInogoreCase))谢谢!这很好用,在c#中简单多了。
    if ((rolesList.Contains("admin")) || (rolesList.Contains("Admin")))
    {
        reportViewerPrintAndExport.ShowPrintButton = true;
        reportViewerPrintAndExport.ShowExportControls = true;
    }
    else if ((rolesList.Contains("Operator")) || (rolesList.Contains("operator")))
    {
        reportViewerPrintAndExport.ShowPrintButton = false;
        reportViewerPrintAndExport.ShowExportControls = false;
    }