Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one , i have a while statement in my little program and i want to create button until the while statement is working
how can i do that ?


C#
int Counter=0;
while(Counter<10)
{

// create button !

Counter++;
}
Posted
Comments
Mehdi Gholam 17-Feb-13 2:18am    
Using what technology?
mahmii 17-Feb-13 2:44am    
C#, R u iranian mr mehdi gholam ? :D
Mehdi Gholam 17-Feb-13 2:46am    
WinForms / Web ...?
mahmii 17-Feb-13 2:53am    
winForm

1 solution

What's the problem with:
C#
int Counter=0;
while(Counter<10)
{

// create button !
Button myButton = new Button();
myButton.ID = "btnNumber" + Counter;
myButton.Text = "btnNumber" + Counter;
somePlaceholderOrPanel.Controls.Add(myButton);

Counter++;
}
 
Share this answer
 
Comments
mahmii 17-Feb-13 2:38am    
hey man , your code is not working ! i cant find any ID property!
myButton object that create have Name property but not ID !!!
any way
i ran this Code :
while(counter<10)
{
Button B=new Button();
B.Name="Name:"+Counter.tostring();
B.Text=Counter.tostring();
controls.add(B);
}

its just make a one butten with "0" text !!!
do u have any idea ?!
Sandeep Mewara 17-Feb-13 2:45am    
1. I gave you algo as you have not shared if winforms or webapp or so
2. You do, controls.add - not right. Has to be a defined location in UI somewhere
3. Debug and see, why only once!

Try out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900