This is a migrated thread and some comments may be shown as answers.

Adding Control to RadPanel at Runtime

1 Answer 137 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Savidu
Top achievements
Rank 1
Savidu asked on 20 Jul 2012, 06:06 AM
hi,

I have create a rad panel as below and for the RadPanelBar with the ID "rpbIncludeSections" items are added dynamically.
<telerik:RadPanelBar runat="server" ID="rpbResumeSections" Width="300px" GridLines="Horizontal" >
        <Items>
            <telerik:RadPanelItem ID="rpiResumeSections" runat="server" PreventCollapse="false" Expanded="true" >
                <Items>
                    <telerik:RadPanelItem ID="rpbResumeSectionInfo" runat="server" >
                        <HeaderTemplate>
                            <div style="margin: 10px;">
                                <telerik:RadComboBox runat="server" ID="rcbTemplates" Width="250px" AutoPostBack="true"  OnSelectedIndexChanged="rcbTemplates_OnSelectedIndexChanged"></telerik:RadComboBox>
                            </div>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <!--Dynamically generate a rad panel bar -->
                            <div style="margin: 10px;max-height: 200px; overflow:auto;">
                                <telerik:RadPanelBar runat="server" ID="rpbIncludeSections" GridLines="Horizontal" ExpandMode="MultipleExpandedItems" >
                                </telerik:RadPanelBar>
                            </div>
                             
                            <div style="margin:10px;margin-top: 30px; text-align:right;">
                                <telerik:RadButton  ID="btnPreview" runat="server" OnClick="btnPreview_OnClick"></telerik:RadButton>
                                <telerik:RadButton ID="btnSavePublish" runat="server" OnClick="btnSavePublish_OnClick"></telerik:RadButton>
                                <telerik:RadButton ID="btnPrintCV" runat="server" OnClick="btnPrintCV_OnClick"></telerik:RadButton>                                         
                            </div>
                             
                        </ItemTemplate>                     
 
                    </telerik:RadPanelItem>                   
                </Items>
            </telerik:RadPanelItem>
        </Items>
    </telerik:RadPanelBar>

The components added dynimacally is as follows
RadPanelBar _rpbIncludeSections = (RadPanelBar)rpbResumeSectionInfo.FindControl("rpbIncludeSections");
 
            if (_personID != 0)
            {
                DataSet _Sections = _cvController.GetSectionsFromCVTemplateIDPersonID(int.Parse(e.Value), _personID);
                 
                _rpbIncludeSections.Items.Clear();
                 
                 
                foreach (DataRow _drSection in _Sections.Tables[0].Rows)
                {
                    bool _checked = false;
                    if ((_drSection["Include"].ToString() != "" && bool.Parse(_drSection["Include"].ToString()) == true) || _drSection["Persons_PersonID"].ToString() == "")
                        _checked = true;
 
 
                    RadPanelItem _panelItemLvl1 = new RadPanelItem();
                    _panelItemLvl1.Text = _drSection["CV_Section"].ToString();
                    _panelItemLvl1.Selected = true;
 
                    RadPanelItem _panelItemLvl2 = new RadPanelItem();
 
                    CheckBox _checkBox = new CheckBox();
                    _checkBox.ID = "Savidu";
                    _checkBox.Checked = _checked;
                    _checkBox.Text = Localization.GetString("Include.Text", this.LocalResourceFile);
                    _checkBox.ToolTip = "Check to Include in ude in CV";
                    _checkBox.CssClass = "MarginLeft";
                    _panelItemLvl2.Controls.Add(_checkBox);
 
                    _panelItemLvl1.Items.Add(_panelItemLvl2);
                    _rpbIncludeSections.Items.Add(_panelItemLvl1);
                }
            }

This part works fine the issue comes when the button "btnSavePublish" OnClick method i need to find out whether the check box is checked or not.

For this id some thing like
RadPanelBar _rpbIncludeSections = (RadPanelBar)rpbResumeSectionInfo.FindControl("rpbIncludeSections");

Through the Items attribute i am able to find the added panels. I.e since i have added 2 panels i would be able to access them

_rpbIncludeSections.Items[0].Items[0]

But, there is no way for me to access the added checkbox. I tried with the "Controls" attribute as well but it gave no luck.

Thanks Regards,
Savidu

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 24 Jul 2012, 09:15 AM
Hi Savidu,

There is a help topic on Accessing Controls Inside Templates. I hope you find it helpful.

If you continue to experience problems, please open a support ticket and send us a working sample of the issue.

Greetings,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
PanelBar
Asked by
Savidu
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or