Dynamic PanelItem

3 posts, 0 answers
  1. pmessina
    pmessina avatar
    13 posts
    Member since:
    Feb 2007

    Posted 07 Jul 2008 Link to this post

    I'm trying to do something simple and have done this in the past but am having a bit of coders block. What I'm trying to do is on a button click dynamicaly add a RadPanelItem to a panel bar and populate it with a group of checkboxes. Every time I try to add a control to the underlying item it gets dumped on postback. A much simplified version of my code is below any help would definatly be appriciated. I'm trying to stay away from the Page_PreInit as I would like to put what I am working on in a usercontrol.

    protected

    void btnTEST_Click(object sender, EventArgs e)

    {

    for (int i = 0; i < 1; i++)

    {

    radpanelitem1.Items.Add(NewItem());

    }

    }

    protected

    RadPanelItem NewItem()

    {

    RadPanelItem o = new RadPanelItem("TEST PANEL");

    CheckBox y = new CheckBox();

    y.ID =

    "TestCheckbox";

    o.Controls.Add(y);

    return o;

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

    foreach (RadPanelItem r in radpanelitem1.Items)

    {

    foreach (Control y in r.Controls)

    {

    if (y is CheckBox)

    System.Diagnostics.

    Debug.WriteLine((y as CheckBox).Checked.ToString());

    }

    }

    }

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 08 Jul 2008 Link to this post

    Hi,

    I suggest you add the checkboxes in the page_load event handler on every postback. You can see the attached project for reference.


    All the best,
    Yana
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. pmessina
    pmessina avatar
    13 posts
    Member since:
    Feb 2007

    Posted 08 Jul 2008 Link to this post

    Thank you very much for the test project and the prompt reply the test file is working and should be able to modify it the way I need it to. Again thank you.
Back to Top