| Author: arun kumar 05 Jul 2008 | Member Level: Silver | Rating: Points: 3 |
ListItem li = new ListItem(TextBox1.Text); if (!ListBox1.Items.Contains(li)) { ListBox1.Items.Add(TextBox1.Text); } else { Response.Write("repeated"); }
|
| Author: mohan 06 Jul 2008 | Member Level: Silver | Rating: Points: 3 |
Your error is index is out of range. It is because listbox has N items you are counting them from 0. So the last listitem index is N-1.But you are counting upto N.So it is giving as error.
Let me know it is useful to u or not.......
|
| Author: Sabu C Alex 06 Jul 2008 | Member Level: Gold | Rating: Points: 3 |
hi friend, try this code
int i; for (i = 0; i <= ListBox1.Items.Count-1; i++) { if (TextBox1.Text!=ListBox1.Items[i].Text) { ListBox1.Items.Add(TextBox1.Text); } else { Response.Write("repeated"); } }
|
| Author: Jessie 07 Jul 2008 | Member Level: Gold | Rating: Points: 2 |
The "=" in "i <= ListBox1.Items.Count" is the culprit. Remove it and rewrite as
i<ListBox1.Items.Count
|