vb.NET中文本框文本与列表框项文本的比较
如何在vb.NET中比较文本框文本和列表框项目文本…请提供帮助vb.NET中文本框文本与列表框项文本的比较,.net,vb.net,text,textbox,listbox,.net,Vb.net,Text,Textbox,Listbox,如何在vb.NET中比较文本框文本和列表框项目文本…请提供帮助 Dim text As String = Me.TxtName.Text For Each item As Object In Me.ListBox1.Items If item.ToString = text Then 'Do something' Else 'Do something else' End If Next </div> <asp:ListB
Dim text As String = Me.TxtName.Text
For Each item As Object In Me.ListBox1.Items
If item.ToString = text Then
'Do something'
Else
'Do something else'
End If
Next
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>zero</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
如果使用自定义对象作为Listbox的数据源,请在类中重写以将它们与Textbox的文本进行比较。
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>zero</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
例如:
Class FooClass
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Overrides Function ToString() As String
Return Me.Name
End Function
End Class
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>zero</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
我在VB.net中尝试了以下内容 它工作得很好
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>zero</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
aspx页面
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>zero</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
结束课程到目前为止,您尝试了哪些不起作用的内容,您想了解哪些内容?我将完整的asp.net页面代码和代码放在下面,它运行良好,希望这对您有所帮助
</div>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>zero</asp:ListItem>
<asp:ListItem>first</asp:ListItem>
<asp:ListItem>second</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
Dim tempInt = lbTeams.Items.Count - 1
While (tempInt > -1)
If (lbTeams.GetItemText(lbTeams.Items.Item(tempInt)).ToString().Equals(txtTeamName.Text) = True) Then
MsgBox("Team Already Exist")
Exit Sub
End If
tempInt -= 1
End While