If the List you have created already has the items the DB contains then simply by the foreach loop. In my understanding you have created this code in an event that runs only one time or does not run as many times as needed. One solution would be to create a script in the front that will make use of the changed() method so every time the textbox text changes this code will run:
script language = javascript>
function txtChanged( TextBoxID)
{
<%# ValidateExistance() %>
}
</script>
Another way would be to put this code inside an event that it will be sure to run everytime the state of the control changes. One way to do that is to go on design mode in the aspx file and double click the textBox. Once you do that, an event will be created in the code behind that will be probably named: textboxText_Changed()
This event will run everytime the text changes according its name. Put this code inside of that event.
foreach(var item in h){
if(item.CategoryName.Contains(textbox1.text.ToString())
{
return false;
}
else
{
return true;
}
}
return false;
I hope this will work.... Best wishes!