Listbox items values comparision

Posted by Ecethatha under ASP.NET on 4/19/2010 | Views : 2651 | Status : [Member] | Replies : 2
Main aim of dis program is i have to generate random numbers. If dat number is generated once it should display dat number is generated. If not added to list box it shud add listbox . If 50 numbers are generated . now i can abe to see whose numbers are generated in a seperate list box .. HOw can I??

random rm;

int i=rm.next(1,100);

if(listbox.items.contains(i))

{

label1.text="Dis item is existed";

}

else

{

listbox.items.add(i);

}




Responses

Posted by: Syedshakeer on: 4/19/2010 [Member] Starter

Up
0
Down
Below code is for to check random number exit or not:- int rand=number; bool flag=true; for(int i=0; i<listbox1.Items.Count; i++) {if(rand== listbox1.Items [ i ].Text) { lbl.Text="already exist";flag=false;} if(flag==true){ listbox1.Items.Add(rand) }

Syed Shakeer Hussain

Ecethatha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/21/2010 [Member] Bronze

Up
0
Down
Random rm;
ListBox listbox = new ListBox();
int i = rm.Next(1, 100);

if (listbox.Items.Contains(new ListItem(i.ToString())))
{
// msg already exists
}
else
{
listbox.Items.Add(i.ToString());
}

Thanks
Pavan Kumar
Mark Answer if this fits the need

Ecethatha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response