Dynamically creating controls and accessing them
-
Hi guys. Im doing a project at the moment that requires the user to select what categories they want to be registered for via check boxes. BUT there arent set categories(and no set number), so they must be read from the database, and then the controls must be generated. So what I have done is put a place holder and then just create new controls in the while read loop of the database. Two problems though: 1) How do I name these(incrementally?)? I cant say
CheckBox chkBx + "i" = new CheckBox();
- Even if I could incrememnt their names how would I see what they had checked once they click ok? I thought about
lblStuff.Text += ""
(ignore the xmlns :-/ ) But that still leaves the second problem. Am I going about this the wrong way? Thanks guys :)
-
Hi guys. Im doing a project at the moment that requires the user to select what categories they want to be registered for via check boxes. BUT there arent set categories(and no set number), so they must be read from the database, and then the controls must be generated. So what I have done is put a place holder and then just create new controls in the while read loop of the database. Two problems though: 1) How do I name these(incrementally?)? I cant say
CheckBox chkBx + "i" = new CheckBox();
- Even if I could incrememnt their names how would I see what they had checked once they click ok? I thought about
lblStuff.Text += ""
(ignore the xmlns :-/ ) But that still leaves the second problem. Am I going about this the wrong way? Thanks guys :)
you can use CheckBoxList instead of creating Checkbox Dynamically.. and for CheckBoxList you can Bind the values form Database.. and onclick of OK, you can loop through CheckBoxList.Items.Count to check which is Selected and You can take only Selected Values..
-
you can use CheckBoxList instead of creating Checkbox Dynamically.. and for CheckBoxList you can Bind the values form Database.. and onclick of OK, you can loop through CheckBoxList.Items.Count to check which is Selected and You can take only Selected Values..
Perfect :D Thanks, really appreciate it!