Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Panelbar > Checkbox in top part of panelbar
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered Checkbox in top part of panelbar

Feed from this thread
  • Karl Wilkens Master avatar

    Posted on Apr 10, 2008 (permalink)

    Is it possible to put a checkbox in the top title part of the panelbar that will when checked, open the panel and display items for that section... instead of a click on any part of the panel? Just wondering. Thanks.

  • Paul Paul admin's avatar

    Posted on Apr 11, 2008 (permalink)

    Hi Karl,

    Please refer to our First Level Templates example for details on the matter. In the code tabs below the example you can find the code used.

    Sincerely yours,
    Paul
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Posted on Apr 11, 2008 (permalink)

    Hi Karl,

    Try adding the CheckBox control in the ItemTemplate of a PanelBar as shown below.

    ASPX:
    <rad:RadPanelbar ID="RadPanelbar1" runat="server">  
                <Items > 
                   <rad:RadPanelItem Text="Place" runat="server"  > 
                   <Items> 
                     <rad:RadPanelItem Text="Delhi" runat="server" > 
                       
                     </rad:RadPanelItem> 
                     <rad:RadPanelItem Text="Banglr" runat="server" ></rad:RadPanelItem> 
                       
                   </Items> 
                     <ItemTemplate> 
                         <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="True" /> 
                     </ItemTemplate> 
                   </rad:RadPanelItem> 
                     
                </Items> 
            </rad:RadPanelbar> 


    CS:
        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)  
        {  
            foreach (RadPanelItem item in RadPanelbar1.Items)  
            {  
                item.Expanded = true;  
            }  
        } 


    Princy.

  • Karl Wilkens Master avatar

    Posted on Apr 11, 2008 (permalink)

    Thanks - that part is easy and now I know it can be done. But now for the challenging part - how do you dynamically add ItemTemplates and associated templated items to an existing RadPanelBar??

  • Paul Paul admin's avatar

    Posted on Apr 11, 2008 (permalink)

    Hi Karl,

    Please find below a sample code snippet that shows the approach.

    protected void Page_Load(object sender, EventArgs e)  
    {  
        RadPanelItem myRootItem = (RadPanelItem)RadPanelBar1.FindItemByText("Root RadPanelItem1");  
     
        HtmlGenericControl myDiv = new HtmlGenericControl("div");  
        myDiv.Attributes["style"] = "margin-top: -25px; float: right;";  
        myRootItem.Controls.Add(myDiv);  
     
        CheckBox myCBox = new CheckBox();  
        myDiv.Controls.Add(myCBox);  


    Regards,
    Paul
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Karl Wilkens Master avatar

    Posted on Apr 11, 2008 (permalink)

    Fantastic - thanks.

    One last challenge - I am adding checkbox lists as sub items and the appearance - no matter what I do

    set panelItem.Expanded = false

    RadPanelBar1.ExpandedMode=Single.. multiple

    it makes no difference.


    the panels initially present as fully expanded showing all items. Any thoughts on how to force these to be initially closed?

  • Karl Wilkens Master avatar

    Posted on Apr 13, 2008 (permalink)

    Thanks for your help. I am still struggling with one thing. If we dynamically add controls to the panelbar items, how do we programmatically get the value of the controls later. In my app, we loop through the entire controls collection.

    Dim chk1 as new checkBox
    chk1.id = "chk1"
    chk1.checked = false

    Dim pi As New RadPanelItem
    pi.Controls.Add(chk1)
    RadPanelbar1.Items.Add(chk1)

    ' Then later, I want to do this

     Dim ctrl As Control


                    Dim pi As Telerik.WebControls.RadPanelItem
                    For Each pi In RadPanelbar1.Items
                        For Each Ctrl In pi.Controls
                            ' test for control type, get value here
                             ' but all I see here are radpanelItems
                        Next
                    Next



  • Paul Paul admin's avatar

    Posted on Apr 14, 2008 (permalink)

    Hi Karl,

    The FindControl method provides you with a reference to any control inside any of the templates used in the RadPanelBar or any of its PanelItems. You must make sure that you properly typecast the returned value as FindControl returns a reference to a Control class.

    After you get the reference you may modify any properties of the referenced control. For details on the matter, please take a look at the following example - Accessing Nested Controls.

    Sincerely yours,
    Paul
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  • Posted on Nov 29, 2010 (permalink)

    I know its old but I found this posting as I need to do a similar thing.

    I have attached an image showing what I get when I try the demo supplied after modifiying it to work with the current controls.

    Figure 1 shows the panel (collapsed) with a text box added instead of a checkbox to the ItemTemplate

    Figure 2 shows the same panel but expanded.

    Figure 3 shows what I'd like to be able to do so that when I add more panels I have something that looks like Figure 4 (obviously the text in the panels would change)

    Can anyone help or let me know if this is even possible? If not I'll have to ditch the panel bar entirely and code it all by hand I think, and I'd rather not!

    Thanks,
    Karl
    (a different Karl to the original poster btw)
    Attached files

  • Yana Yana admin's avatar

    Posted on Dec 2, 2010 (permalink)

    Hello Karl,

    Please check this online example which demonstrates RadPanelBar's HeaderTemplate and ContentTemplate. Note that they're available in the latest Q3 2010 release.

    Kind regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Posted on Dec 2, 2010 (permalink)

    Excellent, this looks like it's exactly what I need to use to get the job done.

    However, I need to build the panels dynamically as there will be an unknown number of them, each with a dynamically built rad grid in its contentTemplate

    Are there any examples of how to build panels dynamically including the header and content templates?

    Karl

  • Yana Yana admin's avatar

    Posted on Dec 7, 2010 (permalink)

    Hi Karl,

    I've attached a simple page to demonstrate how to set ContentTemplate and HeaderTemplate at runtime. Please download it and give it a try.

    Kind regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
    Attached files

  • Posted on Dec 7, 2010 (permalink)

    That's excellent, thank you.

    I've had a play with your example and fitted it into my test project, but cant work out how to have the expand and collapse images change depending on the state of the panel?

    Could you post the relevant code that would allow me to do this?

    It seems to ignore the applied custom SkinID too?

    Thanks,
    Karl

  • Posted on Dec 8, 2010 (permalink)

    I've got another issue with the sample you've given me...

    I have successfully applied the header and content templates and can find them in the object model when the page is posted back, but as part of the header, I want to add a HiddenField control and pass in a value when the template is added. Looking at the code, it jumps from Item.ApplyHeaderTemplate to the InstantiateIn method in the template class, and the signature has changed (ApplyHeaderTemplate doesn't take any parameters, but InstantiateIn takes the container!)

    So if I wanted to add a template to the header, which has a HiddenField control and I want to pass the value of the HiddenField control when I add the HeaderTemplate, how would I go about this? What if I wanted to pass in several values to the header template to store a number of different pieces of information there?

  • Yana Yana admin's avatar

    Posted on Dec 13, 2010 (permalink)

    Hi Karl,

    I've attached the modified code to demonstrate how to achieve both requirements. Please download the attachment and try it.

    All the best,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
    Attached files

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Panelbar > Checkbox in top part of panelbar