views:

567

answers:

3

Ok, I know how to do this, but I want to know if this is the BEST way.

I have a table called "Topics" which has a list of topics(obv). I have a page with about 20 (+/-10) check boxes with all the different topics a user can subscribe to. I figured the best way to do this is to make a control array of check boxes and populate it on page load.

The issue is that the check boxes are in a unique arrangement, should I place them on the page and then dynamically populate them on load? Is that the best way to do it? I'm not too familiar with control arrays.

Thanks!

A: 

I don't follow your question. Why would the code care about the arrangement on the page when it loads? Or are you using ASP.NET?

Rudedog =8^D

+2  A: 

Define what you mean by "should I place them on the page".

Do you mean Drag'n'Drop them onto the aspx page? If you did that, you have to copies of each one -- one set created by the page, and a second created by you which replace the first set.

How do the number of checkboxes vary ("20 (+/- 10)")? Are they options coming from a database? Are they fixed, but you just don't know how many yet?

One funkey aspect of ControlCollection, is that a control can only be in one at a time. If you were to try:

 ControlCollection cool = new ControlCollection ();
 coll.Add(Page.Controls[0]);

It will be added to coll, but it will automatically be removed from Page.Controls.

EDITED: (responding to comment) On your codebehind, create the Checkboxes manually (It's been a while since I wrote WebForm code, so I'm voguing a bit here), and place the in an array (an array shouldn't have the problem I mentioned about ControlCollection)

CheckBox[] boxes = new Checkbox[20];
for(int i =0; i< 20; ++i)
{
    boxes[i] = new CheckBox();
    // do stuff here
    Page.Controls.Add(boxes[i]);
}

Now for the "do stuff here", we need to get them in the right place. There are a number of ways. We can build a <table> around them; we can have <asp:placeholder> controls in the aspx which we add them too; we can set the CSS style position attributes.

James Curran
The number of check boxes MAY vary by the values given in the database.So, the best way to do it is let the page place the check boxes? I didn't know if I could nudge the page into placing them in a configuration. I want three columns of check boxes. I need to be able to iterate through them.
Sara Chipps
A: 

how can i make array control in design in vb.net