I have various admin pages on my system that allow user to insert a new item or update one. The code I am using to check if the description entered is already in the drop down list is
//loop through each item in ddlX and compare with description entered by user
foreach (ListItem i in ddlX.Items)
{
//check if description matches existing values
if (i.Text == a.XDescription)
{
//set boolean value
XExists = true;
//set panel visiblity
pnlInsertSuccess.Visible = false;
pnlInsertError.Visible = true;
lblInsertError.Text = "Insert cancelled - item already exists";
}
}
if (!XExists)
{
try
{
//insert object into database
XManager.InsertX(a);
//set panel visibility
pnlInsertSuccess.Visible = true;
pnlInsertError.Visible = false;
//display success message
lblInsertSuccess.Text = "item '" + X.Text + "' inserted successfully";
ddlX.Items.Clear();
ListItem i = new ListItem("Please Select ... ", "0");
ddlX.Items.Add(i);
ddlX.AppendDataBoundItems = true;
ddlX.DataBind();
}
catch (Exception ex)
{
pnlInsertSuccess.Visible = false;
pnlInsertError.Visible = true;
lblInsertSuccess.Text = "Error Inserting - " + ex.Message.ToString();
}
}
I am using this code on other admin pages and it works perfectly but for here it doesn't, debugging has brought to my attention it is only comparing the text the user entered with the first item in the drop down 'Please Select ...'
anyone know how I can fix this?
Thanks in advance