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

ComboBox ItemTemplate Non Bound Issue

4 Answers 115 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brian Mains
Top achievements
Rank 1
Brian Mains asked on 05 Jan 2009, 07:30 PM
Hello,

I have a combo box with an ItemTemplate, and I bind a range of items to the combo box.  But I add programmatically one item to the list using:

cbo.Items.Add(new RadComboBoxItem("-None-", "None"));

To create the user interface, do I have to add controls to that RadComboBoxItem, or is there another way?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Jan 2009, 07:15 AM
Hello Brian,

Try setting the AppendDataBoundItems property of the combobox to true and then try adding an item using the same code.
aspx:
 <telerik:RadComboBox ID="RadComboBox4" DataSourceID="SqlDataSource2"  AutoPostBack="true" AppendDataBoundItems="true" HighlightTemplatedItems="true"  runat="server" OnTextChanged="RadComboBox4_TextChanged" OnItemDataBound="RadComboBox4_ItemDataBound" OnPreRender="RadComboBox4_PreRender"
      <ItemTemplate> 
      <div class="comboItem"
         <%# DataBinder.Eval(Container.DataItem, "ProductName")%>       
      </div>       
      </ItemTemplate>       
</telerik:RadComboBox> 

Thanks
Princy.
0
Brian Mains
Top achievements
Rank 1
answered on 06 Jan 2009, 01:35 PM
Hello,

I do have AppendDataBoundItems set to true; the item does appear in the list when I do:

rcb.Items.Add(new RadComboBoxItem(..));

Typing in the - None - with MarkFirstMatch="true" does select the item, but in the drop down the item in the list that represents - None - is blank.  It does not display the text for the item in the list, presumably because of the template I would assume...

Thanks.
0
Accepted
Yana
Telerik team
answered on 06 Jan 2009, 03:05 PM
Hi Brian,

The templates of RadComboBox are applied to all items, that's why you cannot add items like this. I've prepared a sample project which shows how you can add items to the databound combobox with templates. Please download the attached file and give it a try.

All the best,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Brian Mains
Top achievements
Rank 1
answered on 06 Jan 2009, 03:36 PM
That sample worked. Thanks.
Tags
ComboBox
Asked by
Brian Mains
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Brian Mains
Top achievements
Rank 1
Yana
Telerik team
Share this question
or