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

PanelBar DataBinding Subcontrols

1 Answer 82 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
itmanager@malibuboats.com
Top achievements
Rank 1
itmanager@malibuboats.com asked on 23 Mar 2009, 09:39 PM
I have a PanelBar that is databounded to a list via the code behind.  Inside the PanelBar I want a template that has a control inside it and the control is databounded OnItemDataBound of the PanelBar by getting a value from the PanelBarItem.  The issue I'm having is that I can't find the control to bind to it.  The code throws a null reference exception on line 27 of the code behind below.

Here is the html markup
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikTest._Default" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">  
            </telerik:RadScriptManager> 
            <telerik:RadFormDecorator ID="RadFormDecorator1" Runat="server" /> 
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="PanelBar1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <telerik:RadPanelBar      
                    ID="PanelBar1"      
                    runat="server"      
                    OnItemDataBound="PanelBar1_OnItemDataBound"    
                    Skin="Vista"    
                    DataTextField="Name"    
                    DataValueField="ID"    
                    ExpandMode="SingleExpandedItem"    
                    >    
                    <Items>    
                            <telerik:RadPanelItem Value="SubItem" runat="server">     
                                    <ItemTemplate>    
                                            <asp:Repeater     
                                                    ID="SubItemList"      
                                                    runat="server">     
                                                    <ItemTemplate>    
                                                            <asp:CheckBox      
                                                                    id="uiItem"      
                                                                    runat="server"      
                                                                    Text='<%# DataBinder.Eval(Container.DataItem, "Name").ToString() %>'      
                                                                    />    
                                                            <br />    
                                                    </ItemTemplate>    
                                            </asp:Repeater>    
                                    </ItemTemplate>    
                            </telerik:RadPanelItem>    
                    </Items>    
            </telerik:RadPanelBar>    
 
    </div> 
    </form> 
</body> 
</html> 
 

Code Behind
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
 
namespace TelerikTest  
{  
    public partial class _Default : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            List<ParentItem> pLst = new List<ParentItem>();  
 
            for (int i = 0; i < 10; i++)  
            {  
                pLst.Add(new ParentItem(i, string.Format("Parent {0}", i.ToString())));  
            }  
 
            PanelBar1.DataSource = pLst;  
            PanelBar1.DataBind();  
        }  
 
        protected void PanelBar1_OnItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)  
        {  
            Repeater subItem = (Repeater)e.Item.Items.FindItemByValue("SubItem").FindControl("SubItemList");  
 
 
            int ID = int.Parse(e.Item.Value);  
            subItem.DataSource = GetItems(ID).Values;  
            subItem.DataBind();  
        }  
 
        private SortedList<int, CustomItem> GetItems(int ID)  
        {  
            SortedList<int, CustomItem> lst = new SortedList<int, CustomItem>();  
 
            for (int i = 0; i < 10; i++)  
            {  
                CustomItem item = new CustomItem(i, string.Format("Item {0}", i), ID);  
 
                lst.Add(i, item);  
            }  
 
            return lst;  
        }  
    }  
 
    public class CustomItem  
    {  
        public int ID { getset; }  
        public string Name { getset; }  
        public int ParentID { getset; }  
 
        public CustomItem(int id, string name, int parentID)  
        {  
            ID = id;  
            Name = name;  
            ParentID = parentID;  
        }  
    }  
 
    public class ParentItem  
    {  
        public int ID { getset; }  
        public string Name { getset; }  
 
        public ParentItem(int id, string name)  
        {  
            ID = id;  
            Name = name;  
        }  
    }  
}  
 


1 Answer, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 24 Mar 2009, 09:36 AM
Hello Yer Yang,

It will be best if you can open a support ticket and send us a simple running project (incl. your custom skin, CSS, images, DB backup if needed and so on) demonstrating the problem (and step-by-step instructions on doing so). In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.

All the best,
Paul
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
PanelBar
Asked by
itmanager@malibuboats.com
Top achievements
Rank 1
Answers by
Paul
Telerik team
Share this question
or