Click here to Skip to main content
12,997,210 members (76,125 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Panel pan = (Panel) this.tabPage1.Controls.Find("a" + i.ToString(),true);
            CheckBox ck = (CheckBox)this.tabPage1.Controls.Find("check" + i.ToString(), true);

in above code that i am creating number of panels dynamically in application)and in that each panel that am addng the checkboxs dynamically

here my requirement is that accessing the particular checked checkbox and writintg the value to the corresponding database

in above code that ai means (a1,a2,a3.........)panels created dynamically
checki means (check1,check2,.........)checkboxs created dynamically
what is the error in it
and how should i access it

more over i am getting the error as
1).cannot converttype[] to
2).cannot converttype[] to
Posted 13-Aug-10 2:34am
Updated 13-Aug-10 2:42am
E.F. Nijboer 13-Aug-10 8:49am
If you set a breakpoint and go look at the names of the dynamically created controls, are the names as you expected (and when you break in the loop, does it equals "a" + i.ToString())? Are you sure their parent is the tabpage you are looking on? Step through it with the debugger and sure to find it quick and easy.
samqty 13-Aug-10 16:10pm
am confused here ... why are you looking for the panel in the first place ... I mean you are looking for the checkbox in the tabpage??? if you added the checkboxes in the panels then you should be looking for the checkbox inside the panel.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try something like:
Panel pan = (Panel)this.tabPage1.Controls.Find("a" + i.ToString(), true)[0];
CheckBox ck = (CheckBox)this.tabPage1.Controls.Find("check" + i.ToString(), true)[0];

Of course you should also check if the control you're looking for exists at all and is indeed a checkbox or panel:

            Control[] panels = this.tabPage1.Controls.Find("a" + i.ToString(), true);
            Panel pan = null;
            CheckBox ck = null;
            if (panels.Length > 0 && panels[0] is Panel)
                pan = (Panel)panels[0];
                //The panel does not exist - do whatever you think is appropriate
            Control[] checkBoxes = this.tabPage1.Controls.Find("check" + i.ToString(), true);
            if (checkBoxes.Length > 0 && checkBoxes[0] is CheckBox)
                ck = (CheckBox)checkBoxes[0];
                //Checkbox doesn't exist 
sivakumarmr10 14-Aug-10 4:37am
Reason for my vote of 5
perfect one matching answer

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 13 Aug 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100