Click here to Skip to main content
16,013,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I have a webpage, with a wizard on it. In the wizard I dynamically created Accordions, and in the accordions, there are dynamically created checkboxes. It works fine, but I need to put the checked textbox id-s in to a list, when the user clicks next. My problem is, that I don't know, how to get wich textboxes are checked.

Here is my code:
C#
private void PopulateAcrDynamically()
    {
        List<string[]> parameterek = new List<string[]>();

        int M1 = 1;

        parameterek.Add(new string[3] { "@M1", "SqlDbType.Int", M1.ToString() });

        DataTable eredmeny = AdatEleres.TaroltEljarasHivas("GetCompetenciesByMandatory", parameterek);

        parameterek.Clear();

        DataTable Behaviors = new DataTable();
        DataTable Questions = new DataTable();
        if (eredmeny.Rows.Count != 0)
        {
            Label lbTitle;
            GridView gvContent;
            GridView gvQuestions;
            AjaxControlToolkit.AccordionPane pn;
            int i = 0;

        foreach (DataRow dr in eredmeny.Rows)
        {
                int k = 0;
                k++;
                parameterek.Add(new string[3] { "@CompID", "SqlDbType.Int", dr[0].ToString() });
                Behaviors = AdatEleres.TaroltEljarasHivas("GetBehaviors", parameterek);
                parameterek.Clear();

                parameterek.Add(new string[3] { "@CompID", "SqlDbType.Int", dr[0].ToString() });
                Questions = AdatEleres.TaroltEljarasHivas("GetQuestions", parameterek);
                parameterek.Clear();

                lbTitle = new Label();
                gvContent = new GridView();
                gvQuestions = new GridView();

                gvContent.DataSource = Behaviors;
                gvContent.DataBind();

                gvContent.HeaderRow.Visible = false;
                gvContent.HorizontalAlign = HorizontalAlign.Left;

                foreach (GridViewRow gvr in gvContent.Rows)
                {
                    gvr.Cells[0].Visible = false;
                    gvr.Cells[1].Visible = false;
                }

                gvQuestions.DataSource = Questions;
                gvQuestions.DataBind();

                gvQuestions.HeaderRow.Visible = false;
                gvQuestions.HorizontalAlign = HorizontalAlign.Center;

                foreach (GridViewRow gvr in gvQuestions.Rows)
                {
                    gvr.Cells[0].Visible = false;
                    gvr.Cells[1].Visible = false;
                }

                cbSelect = new CheckBox();
                cbSelect.Text = "Kiválasztás";
                cbSelect.ID = dr[0].ToString();

                lbTitle.Text = dr["Name"].ToString();
                pn = new AjaxControlToolkit.AccordionPane();
                pn.ID = "Pane" + i;
                pn.HeaderContainer.Controls.Add(lbTitle);
                pn.ContentContainer.Controls.Add(gvContent);
                pn.ContentContainer.Controls.Add(gvQuestions);
                pn.ContentContainer.Controls.Add(new LiteralControl("<p />"));
                pn.ContentContainer.Controls.Add(cbSelect);
                Accordion1.Panes.Add(pn);
                ++i;
            }
        }


Thanking you in advance for your answers.
Posted

Assuming that you are wanted to read values at client side using javascript below is the url you can refer.

how to access checkboxes and their values with getElementsByName[^]

Below url shows how to access checkbox values using jQuery

Get checkbox value in jQuery[^]
 
Share this answer
 
Ok, I've made it:

C#
foreach (Control pane in Accordion1.Panes)
            {
                //Check the controls in the Accordions Content
                foreach (Control item in pane.Controls[1].Controls) 
                {
                    //Is it a CheckBox? I have multiple controls, but only 1 CheckBox
                    if (item is CheckBox)
                    {
                        //Check if it's checked
                        if (((CheckBox)item).Checked == true)
                        {
                            lstID.Add(item.ID);
                        }
                    }
                }
            }

This will give back the ID of the checkbox when, if it's checked a button is clicked.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900