复合IF ELSE Statment无法正常工作

复合IF ELSE Statment无法正常工作

问题描述:

我有一个网页表单,可以打印出不同级别的不同报告。所有报告都打印出来,但没有报告40%和50%的变化。我复合IF语句,它仍然无法正常工作。我做错了什么?



I have a web form that prints out different reports on different levels. All of the reports print out but not the report for the 40% and 50% change. I compound the IF statement and it still does not work. What did I do wrong?

if (Page.IsValid)
                {
                    int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
                    int iTextBoxHC50 = Convert.ToInt32(TextBoxHC50.Text);
                    


                    if (iTextBoxFTE40 > 40)
                        if (iTextBoxHC50 > 50)
                    {
                        TextBoxINST_ID.Text = Session["inst_id"].ToString();
                        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }

                    else if (iTextBoxHC50 > 50)
                    {
                        TextBoxINST_ID.Text = Session["inst_id"].ToString();
                        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE50.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (iTextBoxFTE40 > 40)
                    {
                        TextBoxINST_ID.Text = Session["inst_id"].ToString();
                        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE40.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (iTextBoxFTE40 < 40)
                    {
                        TextBoxINST_ID.Text = Session["inst_id"].ToString();
                        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('ReportFormFTE.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
                    }

为了善良,请理清你的缩进! :笑:

这很容易做 - 如果你的代码编译,那么CTRL + K CTRL + D就可以了。



但是...你需要先修复编译错误。

从你的字符串开始:

For goodness sakes, sort out your indentation! :laugh:
It's easy enough to do - if your code compiles, then CTRL+K CTRL+D will do it.

But...you need to fix the compilation errors first.
Start with your strings:
ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language="javascript">window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");



无法编译因为嵌入式双引号终止字符串。尝试:


Won't compile becasue teh "embedded" double quotes terminate the string. Try:

ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=\"javascript\">window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");





然后,你可以格式化它,VS会更清楚地看到代码:



Then, you can format it, and it's clearer how VS will see the code:

if (Page.IsValid)
    {
    int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
    int iTextBoxHC50 = Convert.ToInt32(TextBoxFTE50.Text);



    if (iTextBoxFTE40 > 40)
        if (iTextBoxHC50 > 50)
            {
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=\"javascript\">window.open('ReportFormFTE4050.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }

        else if (iTextBoxHC50 > 50)
            {
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=\"javascript\">window.open('ReportFormFTE50.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }
        else if (iTextBoxFTE40 > 40)
            {
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=\"javascript\">window.open('ReportFormFTE40.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }
        else if (iTextBoxFTE40 < 40)
            {
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=\"javascript\">window.open('ReportFormFTE.aspx','PrintMe','height=650px,width=950px,scrollbars=1');</script>");
            ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }

    }





所以现在,你可以看到你的如果s在做:



So now, you can see what your "if"s are doing:

if (Page.IsValid)
    {
    int iTextBoxFTE40 = Convert.ToInt32(TextBoxFTE40.Text);
    int iTextBoxHC50 = Convert.ToInt32(TextBoxFTE50.Text);
    if (iTextBoxFTE40 > 40)
        if (iTextBoxHC50 > 50)
            {
            }

        else if (iTextBoxHC50 > 50)
            {
            }
        else if (iTextBoxFTE40 > 40)
            {
            }
        else if (iTextBoxFTE40 < 40)
            {
            }
    }

然后很明显,这不起作用!

第一个else if与它上面的if条件相同!

And then it's obvious that that won't work!
The first "else if" is the same as the "if" condition above it!