【发布时间】:2013-03-21 03:22:22
【问题描述】:
在添加新项目之前,我正在尝试检查列表框中是否存在项目。
if (TeamNameTextBox.Text != "")
{
if (TeamNameListBox.Items.FindByValue(TeamNameListBox.Text) == null)
{
TeamNameListBox.Items.Add(TeamNameTextBox.Text);
TeamNameTextBox.Text = "";
int teamCountUpdate = TeamNameListBox.Items.Count;
if (teamCountUpdate == 1)
{
TeamCount.Text = teamCountUpdate.ToString() + " Team";
}
else
{
TeamCount.Text = teamCountUpdate.ToString() + " Teams";
}
}
else
{
AddTeamSeasonError.Text = "This team has already been added";
}
}
else
{
AddTeamSeasonError.Text = "Please select a team";
}
我有它来检查文本框是否为空白,但我需要检查用户尝试添加的项目是否不在列表框中。
我试过这条线:
if (TeamNameListBox.Items.FindByValue(TeamNameListBox.Text) == null)
但这不起作用,关于如何进行检查有什么建议吗?
【问题讨论】:
-
请不要多次发布同一个问题。我投票结束你问的另一个问题。谢谢。