Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using RadPanelBar to show items and i need to add some controls under each item. I was able to build the control and i can see the control with a text box. But iam getting null object when i try to access the controls with findcontrol method in a button click event. Here the code i am using in this example. I would appreciate your help.

UI:
<telerik:RadPanelBar ID="RadPanelBar"  runat="server" Width="60%">
    <ExpandAnimation Type="None" />
     <CollapseAnimation Type="None" />
 </telerik:RadPanelBar>

 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />


Code behind:
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadFaqs();
            }
        }

        private void LoadFaqs()
        {
            List<Model.FAQCategory> FaqCategories = FaqHelper.GetFaqCategories();
            List<Model.FAQ> FaqsByCategory = null;

            int count = FaqCategories.Count;
            foreach (Model.FAQCategory faqCat in FaqCategories)
            {
                if (count > 0)
                {
                    // Populate parent
                    RadPanelItem PanelItem = new RadPanelItem();
                    PanelItem.Value = faqCat.FAQCategoryID.ToString();
                    PanelItem.Text = faqCat.Description;
                    PanelItem.Expanded = true;

                    TextBox txtTest = new TextBox();
                    txtTest.ID = "txtTest";
                    RadPanelItem ChildlItem = new RadPanelItem();
                    ChildlItem.Value = "ChildlItem" + count.ToString();
                    //ChildlItem.ContentTemplate = new MyRepeaterItemTemplate(txtTest);
                    ChildlItem.Controls.Add(txtTest);



                    //PanelItem.ContentTemplate = new MyRepeaterItemTemplate(txtTest);
                    //PanelItem.Controls.Add(txtTest);
                    PanelItem.Items.Add(ChildlItem);
                    PanelItem.Expanded = false;
                    //PanelItem.DataBind();

                    RadPanelBar.Items.Add(PanelItem);
                    RadPanelBar.ExpandMode = PanelBarExpandMode.SingleExpandedItem;
                }
                count = count - 1;

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //var radPanelItems = RadPanelBar.GetAllItems();


            int itemCount = 0;
            Objects.FollowUp.Faq objFaq;
            string ctrlName;
            foreach (RadPanelItem pnlItem in RadPanelBar.GetAllItems())
            {
                TextBox txt = (TextBox)pnlItem.FindControl("txtTest");
                itemCount = pnlItem.Items.Count;
                if (pnlItem.Items.Count > 0)
                {
                    //Repeater rptQes = (Repeater)pnlItem.FindControl("rptQuestions");
                    //Repeater FaqRepeat = pnlItem
                    foreach (RadPanelItem child in pnlItem.Items)
                    {
                        TextBox txt1 = (TextBox)child.FindControl("txtTest");
                        Repeater rptQes = (Repeater)child.FindControl("rptQuestions");
                    }
                }
            }


        }
        public class MyRepeaterItemTemplate : ITemplate
        {
            Control ctrlToAdd;
            public MyRepeaterItemTemplate(Repeater rptQes)
            {
                ctrlToAdd = (Repeater)rptQes;
            }
            public MyRepeaterItemTemplate(TextBox rptQes)
            {
                ctrlToAdd = (TextBox)rptQes;
            }
            public void InstantiateIn(Control container)
            {
                // do something else
                container.Controls.Add(ctrlToAdd);
            }
        }


What I have tried:

I tried with a simple textbox control with RadPanelBar
Posted
Comments
Vincent Maverick Durano 4-Aug-16 12:26pm    
There may be some here who knows about Telerik controls, but I think you stand a better chance by posting it at Telerik dedicated forums:http://www.telerik.com/community/forums.aspx

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