【发布时间】:2011-07-14 15:45:06
【问题描述】:
我要做的是检查一个值是否与两个数字之一匹配(并且可以轻松添加到要比较的数字中)。而不是做一个冗长的方式,例如:
If Number = 1 Or Number = 2 Then ...
我正在尝试做这样的事情:
If Number In (1,2) Then...
由于In 运算符在VB 中不可用,我尝试了以下代码:
Protected SectionID As Integer = HttpContext.Current.Request.QueryString("sectionid")
Protected PageID As Integer = HttpContext.Current.Request.QueryString("pageid")
Protected Sub HotspotsLV_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles HotspotsLV.ItemDataBound
Dim SecondLineHolder As HtmlControl = e.Item.FindControl("SecondLineHolder")
Select Case True
Case New String("2", "3").Contains(SectionID) : SecondLineHolder.Attributes("style") = "color:#21720B"
Case New String("8", "12").Contains(PageID) : SecondLineHolder.Attributes("style") = "color:#1B45C2"
End Select
End Sub
我发现这仅在 SectionID 为 2 或 PageID 为 8 时有效。如果 SectionID 为 3 或 PageID 为 12,则它不起作用。为什么会这样,我能做些什么来解决这个问题?谢谢。
【问题讨论】:
标签: asp.net vb.net comparison-operators