Telerik.Web.UI.dll v2008.1.619.20
Hi Telerik, trying to upgrade my custom (inherited) ComboBox to the version above from RadComboBox.Net2.dll v2.8.1.0
Inheriting from Combox, ComboBoxItem and creating a custom ItemTemplate (note that ComboBoxItem in this example is not really necessary but my production version has additional attributes added here)
Basically, when I 'databind my control it renders fine, but when I add elements to my cmbo via the <items/> collection in my ASPX page the controls fails to render. I added calls to .DataBind() on the control and the individual items but this doesn't seem to help any ...debugger shows that the ComboBoxTemplate is never instantiated/created for the controls with items declared in the markup.
All was/is fine under the old version?
Thanks for any and all advice
ComboBox.cs
using System; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using Telerik.Web.UI; |
namespace TelerikTestSite |
{ |
public class ComboBox : RadComboBox |
{ |
protected override void OnInit ( EventArgs e ) |
{ |
// set template |
base.ItemTemplate = new ComboBoxTemplate ( ); |
// continue event |
base.OnInit ( e ); |
} |
} |
} |
ComboBoxItem.cs
namespace TelerikTestSite |
{ |
public class ComboBoxItem : RadComboBoxItem |
{ |
public ComboBoxItem ( ) : base ( ) |
{ |
} |
} |
} |
ComboBoxTemplate.cs
using System; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using Telerik.Web.UI; |
namespace TelerikTestSite |
{ |
public class ComboBoxTemplate : ITemplate |
{ |
public void InstantiateIn ( Control container ) |
{ |
CheckBox cb = new CheckBox ( ); |
cb.ID = "cb"; |
cb.DataBinding += new EventHandler ( cb_DataBinding ); |
container.Controls.Add ( cb ); |
} |
void cb_DataBinding ( object sender, EventArgs e ) |
{ |
CheckBox target = (CheckBox) sender; |
RadComboBoxItem item = (RadComboBoxItem) target.BindingContainer; |
target.Text = (string) DataBinder.Eval ( item, "Text" ); |
} |
} |
} |
Default.aspx
<div> |
DataBind ..works: <app:combobox runat="server" id="cb1" /> |
</div> |
<br /> |
<div>Declarative ..fails: |
<app:combobox runat="server" id="cb2" highlighttemplateditems="true"> |
<items> |
<app:comboboxitem text="Item 1" /> |
<app:comboboxitem text="Item 2" /> |
<app:comboboxitem text="Item 3" /> |
</items> |
</app:combobox> |
</div> |
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e) |
{ |
ArrayList al = new ArrayList ( 3 ); |
al.Add ( "Item 1" ); |
al.Add ( "Item 2" ); |
al.Add ( "Item 3" ); |
this.cb1.DataSource = al; |
this.cb1.DataBind ( ); |
foreach ( ComboBoxItem item in cb2.Items ) |
item.DataBind ( ); |
this.cb2.DataBind ( ); |
} |