Can anyone tell me, why I don't get any output with this on buttonclick
?
string searchString = TextBox1.Text;
ArrayList personarraylist = new ArrayList();
foreach (Person a in personarraylist)
{
if (searchString == Convert.ToString(a))
{
personarraylist.Add(a);
}
}
ListBox1.DataSource = personarraylist;
EDIT:
Hi everybody, thanks for your input. I have a class for Person, and all data created on the pages is stored in a file: FileController.ReadFile(Server.MapPath("~/App_Data/Personfile.ser")); This is where I need my data from. I use a Filecontroller class to write and read (also update) to and from the file. But the Search function has just gotten the better part of me. (as a student the data handling in file was required, or I would have used a DB). Hope this clears my code up a little. And do I have to compare the search term to something e g firstName, or can it work through the whole file?
You create a new array list and then immediately foreach
over it. Since you just created it there are no items in it, so the foreach
does nothing.