相当于 VB.NET 中的 SQL IN
我想做的是检查一个值是否与两个数字之一匹配(并且可以轻松地添加到要比较的数字中)。 我没有采用冗长的方式,例如:
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,则它不起作用。这是为什么?我可以采取什么措施来解决这个问题?谢谢。
What I am trying to do is to check if a value matches one of two numbers (and easily be able to add to the numbers to compare to). Rather than doing a longer-winded way such as:
If Number = 1 Or Number = 2 Then ...
I'm trying to do something like this:
If Number In (1,2) Then...
As the In
operator isn't available in VB, I have tried the following code instead:
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
I have found that this only works when SectionID
is 2 or PageID
is 8. If SectionID
is 3 or PageID
is 12 then it doesn't work. Why is this and what can I do to try to get around the problem? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过一番尝试后,我找到了一个很好的解决方案:
After a bit of playing around, I have managed to find a nice solution:
您正在创建一个
String
实例而不是数组。尝试将其更改为:如果您使用
Option Strict On
,则类型不匹配将突出显示。在初始代码中,New String("2", "3")
将创建一个值为222
的字符串。编辑
对于 3.5 之前的 .Net 版本,
Contains
方法将不可用。这可以使用IndexOf
来模仿:You are creating a
String
instance not an array. Try changing it to:If you use
Option Strict On
then the type mismatch would be highlighted. In your initial codeNew String("2", "3")
would create a string with a value of222
.Edit
For .Net version prior to 3.5 the
Contains
method will not be available. This can be mimicked usingIndexOf
: