Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vb.NET中文本框文本与列表框项文本的比较_.net_Vb.net_Text_Textbox_Listbox - Fatal编程技术网

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

如何在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: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