Advertisement

03.20.2008 at 01:17PM PDT, ID: 23258300
[x]
Attachment Details

Need to Find CheckBox Controls in asp:Table

Asked by CJSantora in Programming for ASP.NET, C# Programming Language, Microsoft Visual C#.Net

Tags:

Hi Experts, we have an application taht uses a asp:Table as a object to hold Checkboxes, which are created dynamically at runtime. So the user is populating a database and the records are used to create the checkboxes and build a form. this all works well so far.

However upon submitting the form, I need to reference the check boxes to see which are selected. And I am having difficulty with this. I cannot seem to find the checkboxes. I am attaching some of the code and would appreciate any help that can be offered.

Thank you in advanceStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
Building of checkboxes:
int cnt = 0;
            foreach (DataRowView dr in dv)
            {
 
                if ((cnt % 3) == 0)
                {
                    row = new TableRow();
                    cell = new TableCell();
                    cell.ID = "Cell" + cnt.ToString();
                    cell.CssClass = "style2";
 
                    CheckBox chk = new CheckBox();
                    chk.ID = "chk" + dr["Name"].ToString().Replace(" ", "");
                    chk.Text = dr["Name"].ToString();
                    cell.Controls.Add(chk);
 
                    row.Cells.Add(cell);
                }
                else
                {
                    cell = new TableCell();
                    cell.ID = "Cell" + cnt.ToString();
 
                    CheckBox chk = new CheckBox();
                    chk.ID = "chk" + dr["Name"].ToString().Replace(" ", "");
                    chk.Text = dr["Name"].ToString();
                    cell.Controls.Add(chk);
 
                    row.Cells.Add(cell);
                }
 
                if ((cnt % 3) == 0)
                    tblCategories.Rows.Add(row);
 
                cnt++;
            }
 
Trying to find checkboxes: // this is the Problem
 
            foreach (TableRow row in tblParentCategories.Rows)
            {
                Control ctl = new Control();
                ctl = (Control)row.FindControl();
                if (ctl.GetType() == typeof(CheckBox))
                    if (chk.Checked == true)
                    {
                        chk.Text = (ctl as CheckBox).Text;
                        CategoryName = chk.Text;
                    }
            }
 
Loading Advertisement...
 
[+][-]03.20.2008 at 02:04PM PDT, ID: 21175857

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.20.2008 at 02:08PM PDT, ID: 21175891

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, C# Programming Language, Microsoft Visual C#.Net
Tags: ASP.NET C#
Sign Up Now!
Solution Provided By: MaxOvrdrv2
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.21.2008 at 05:14AM PDT, ID: 21179357

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628