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

Manually Adding RadComboBoxItems - all items are blank

1 Answer 51 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael Hunt
Top achievements
Rank 1
Michael Hunt asked on 30 Aug 2012, 04:03 PM
Hi, I'm using ASP.NET AJAX version 2011.3.1305.35.

I'm trying to do something as simple as:
1)  Add all RadComboBoxItems to the combobox by looping through a List.
2)  Add an Attribute to each RadComboBoxItem, in that same loop.

When I bind the combo box by setting the DataSource Property to my List, the items display as expected. 

PROBLEM:
When I loop through the List and add the items and attributes, all of the items and  attributes are added, but the items do NOT display in the combo box.  The combo box appears blank / empty.

I can tell they are there though, by using a javascript Alert on the selectedindexchanged event of the combo box.

The combo box displays in a Rad Grid row, when the row is in edit mode.
The combo box is populated during the ItemDataBound event of the RadGrid, when the row is put into edit mode.

My code follows (but I've tried a whole bunch of variations of it):

I've tried not doing a DataBind;  I've tried doing the DataBind after adding all of the items, I've tried setting the AppendDataBoundItems property to True.  No matter what I do, my combo box is populated BUT IT displays as being EMPTY / BLANK.

comboBox.DataValueField = "emEventID"
comboBox.DataTextField = "emEventTitle"
comboBox.DataBind()
 
Dim cbItem As RadComboBoxItem
For Each project As EM_EventsItem In filteredEventsList
    cbItem = New RadComboBoxItem(project.emEventTitle, project.emEventID)
    cbItem.Attributes.Add("UserPermissionLevel", project.UserPermissionLevel)
    comboBox.Items.Add(cbItem)
    cbItem.DataBind()
Next

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 03 Sep 2012, 08:16 AM
Hello Michael,

Could you try to add the desired Attributes on the server-side event OnItemDataBound, which will be fired for each added item after the first DataBind() method in the given snippet of code?
In addition, once you have pointed to the DataValueField and the DataTextField values, you don't need to recreate the items with "New RadComboBoxItem".

If the aforementioned approach is not helpful for your scenario, I would like to ask you to open a Support Ticket and provide us a runnable sample, which demonstrates the described problem.


Regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Michael Hunt
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or