1

case是否可以使用带有语句的IFswitch语句?我尝试了以下代码,但没有任何反应。我已经验证 SectionID 不等于 -1 但页面不处理任何内容,它不会触发orServer.Transfer也不会将分配传播到ListViewor Labels

case "Media":
    if (SectionID != "-1") { Server.Transfer("/Staff/Section.aspx"); }
    lvSearchResults.DataSource = SQLHelper.GetDataByQuery("SELECT SectionID AS ID, ShortName AS Title, Synopsis AS Descript, 'Section' AS PageName FROM dbo.tblSectionInfo WHERE  ShortName != 'Unknown' ORDER BY SectionTitle");
    lvSearchResults.DataBind();
    lblTitleRow.Text = "Add Section";
    lblDescriptionRow.Text = "Add new section home page.";
    btnAddNewItem.PostBackUrl = "/Staff/Section.aspx";
break;
4

1 回答 1

1

在 case 语句中编写 if 语句是完全有效的。

你为什么不尝试使用 Response.Redirect 代替?

Response.Redirect("/Staff/Section.aspx" , false);
于 2012-10-03T00:43:17.413 回答