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

[Solved] Combobox items added after binding not getting displayed in dropdown

2 Answers 206 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Siva
Top achievements
Rank 1
Siva asked on 12 Oct 2009, 11:09 AM
Hi there 

I am using the following code to load RadComboBox and insert the RadComboBox with a  text "select item" at the top which is fairly basic, but I am unable to see the text "select item" added when clicking the dropdown.  Please Advice!
[Code and error image attached]

Thanks
Siva

        <telerik:RadComboBox  ID="RadComboBox1" runat="server" Height="190px" Skin="Office2007" 
                        Width="300px" MarkFirstMatch="true"  NoWrap="true" DropDownWidth="420px" EnableLoadOnDemand="true" HighlightTemplatedItems="true" 
                        ItemRequestTimeout="500"
                        <HeaderTemplate> 
                            <ul> 
                                <li class="col1">Company Name</li> 
                            </ul> 
                        </HeaderTemplate> 
                        <ItemTemplate> 
                            <ul> 
                                <li class="col1"><%# DataBinder.Eval(Container.DataItem, "CompanyName") %></li
                            </ul> 
                        </ItemTemplate> 
                    </telerik:RadComboBox> 
  Dim sql As String = "SELECT * from Customers" 
        Dim adapter As New SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString) 
 
        Dim dt As New DataTable() 
        adapter.Fill(dt) 
        RadComboBox1.DataTextField = "CompanyName" 
        RadComboBox1.DataValueField = "City" 
        RadComboBox1.DataSource = dt 
        RadComboBox1.DataBind() 
 
        RadComboBox1.Items.Insert(0, New Telerik.Web.UI.RadComboBoxItem("Select Item""None")) 

2 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 13 Oct 2009, 04:04 PM
Try to add this during the DataBound or PreRender event and see if that fixes it.

DataBound:
protected void RadComboBox1_DataBound(object sender, EventArgs e)   
{  
         RadComboBox1.Items.Insert(0, New Telerik.Web.UI.RadComboBoxItem("Select Item""None"))  

PreRender:
protected void RadComboBox1_PreRender(object sender, EventArgs e)   
{  
         RadComboBox1.Items.Insert(0, New Telerik.Web.UI.RadComboBoxItem("Select Item""None"))  

0
Veselin Vasilev
Telerik team
answered on 15 Oct 2009, 11:51 AM
Hi Siva,

You have defined an ItemTemplate which renders the CompanyName value from the dataItem, but the "Select Item" does not have a dataItem property - so it is not rendered.
I am a bit curious why do you need to use a template in your case since you only show one text field?
You can achieve that behavior without templates very easy - just remove the ItemTemplates and the look should be the same.

If you still want to use templates - you can do the following:

<ItemTemplate>
  <ul>
     <li class="col1"><%# Container.DataItem != null ? DataBinder.Eval(Container.DataItem, "CompanyName") : "Select Item" %></li>
  </ul>
</ItemTemplate>

RadComboBox1.Items.Insert(0, New Telerik.Web.UI.RadComboBoxItem("Select Item", "None"))
RadComboBox1.Items(0).DataBind()

Hope this helps.


Greetings,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ComboBox
Asked by
Siva
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or