Re: 50 Buttons!
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/04/05
- Next message: Jon Skeet [C# MVP]: "Re: Convert Ascii Character to decimal"
- Previous message: Juan T. Llibre: "Re: Home directory in IIS?"
- In reply to: Dennis Myrén: "Re: 50 Buttons!"
- Next in thread: Dennis Myrén: "Re: 50 Buttons!"
- Reply: Dennis Myrén: "Re: 50 Buttons!"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 4 Mar 2005 18:10:42 -0000
Dennis Myrén <dennis@oslokb.no> wrote:
> If your buttons name's follow a pattern, you can use an indexer and loop
> like this.
> Button button = null;
> int buttonIndex = 0x1;
> while (null != (button = base.FindControl(string.Concat("Button",
> buttonIndex ++.ToString())) as Button))
> {
> button.BackColor = System.Drawing.Color.Azure;
> }
Or, much better IMO, would be to have an array of buttons:
Button[] buttons = new Button[50];
Then create the buttons dynamically (rather than with the designer),
say from a list of strings. Then it's really easy to add a particular
event handler to all buttons, etc.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Jon Skeet [C# MVP]: "Re: Convert Ascii Character to decimal"
- Previous message: Juan T. Llibre: "Re: Home directory in IIS?"
- In reply to: Dennis Myrén: "Re: 50 Buttons!"
- Next in thread: Dennis Myrén: "Re: 50 Buttons!"
- Reply: Dennis Myrén: "Re: 50 Buttons!"
- Messages sorted by: [ date ] [ thread ]