我该如何检查一个项是否已存在于Listbox中?我使用的是VS 2008 ASP.NET 3.5框架C#。我用了以下代码...
if (ListBox1.Items.Contains(drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text))
{...}
尝试这个...
string toMatch = drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text;
ListItem item = ListBox1.Items.FindByText(toMatch);
if (item != null)
{
//found
}
else
{
//not found
}
你可以使用这个来检查项目是否存在于列表框中...
string checkitem = drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text;
if ((ListBox1.Items.Contains(checkitem) == true))
{
Response.Write("Item exists");
}
else
{
Response.Write("Item not exists");
}