0

Any one can help... I need to access dynamically added checkboxes in other events I will share my code

void bindMaterials()
{
    try
    {
        SqlConnection Con = new SqlConnection(conString);

        SqlCommand FCimsbindoptCommand = Con.CreateCommand();
        FCimsbindoptCommand.Connection = Con;
        FCimsbindoptCommand.CommandText = "select * from nhcms_privilege";

        SqlDataAdapter FCimsSrchAdapter = new SqlDataAdapter(FCimsbindoptCommand);
        DataTable FCimsSrchDataSet = new DataTable();
        FCimsSrchAdapter.Fill(FCimsSrchDataSet);

        int rowcount = FCimsSrchDataSet.Rows.Count;

        var a = new List<string>();
            foreach (DataRow row in FCimsSrchDataSet.Rows)
            {
                a.Add(row["Privilege_Name"].ToString());
            }
            string[] strdata = a.ToArray();

            foreach (var value in a)
            {
                CheckBox checkbox = new CheckBox();
                checkbox.ID = "chk" + value;
                checkbox.Text = value;

                Panel1.Controls.Add(checkbox);
            }
    }
    catch (Exception e)
    {
    }
}

I want to access these check box controls into button event

Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
Santhosh
  • 59
  • 1
  • 10
  • 1
    Where are you calling `bindMaterials()` it obviously needs to be before you try and access their values. Other than that it should just be a matter of `Panel1.FindControl("ControlId")` – Ben Robinson Oct 31 '14 at 12:46
  • http://stackoverflow.com/questions/26675142/asp-net-cannot-access-to-dynamically-created-controls/26675340#26675413 – Igor Oct 31 '14 at 14:01
  • If they're a list (it appears to be based on your code), you could just use a CheckboxList, get the control then iterate the items in it to find whether they're checked or not. – Tim Oct 31 '14 at 14:28
  • Now every thing is working... but can not accessing check box id in other event calling from other event not in page load.. – Santhosh Nov 03 '14 at 10:28

0 Answers0