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

How to remove a blank row in combobox

1 Answer 463 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 26 Jun 2013, 04:02 AM

i insert a item to the radcombobox by code behind.

<telerik:RadComboBox runat="server" ID="RadComboBox_Project" EnableOverlay="true"
                      DataTextField="DisplayName"  DataValueField="ProjectID" Skin="Sunset"
                              EnableLoadOnDemand="True" DataSourceID="ObjectDataSource2"
                      OnSelectedIndexChanged="RadComboBox_Project_SelectedIndexChanged" AutoPostBack="True"
                              HighlightTemplatedItems="true" Label="" Width="100%" NoWrap="True">
                              <HeaderTemplate>
                                   <ul>
                                        <li class="col1">Project Number | Project Name</li>
                                        <%--<li class="col2"></li>--%>
                                   </ul>
                              </HeaderTemplate>
                              <ItemTemplate>
                                   <ul>
                                        <li class="col1"><%# Eval("ProjectNumber") + " | " + Eval("ProjectName")%></li>
                                        <%--<li class="col2"><%# Eval("ProjectName") %></li>--%>
                                   </ul>
                              </ItemTemplate>
<%--                              <Items>
                                            <telerik:RadComboBoxItem Text="Select a Project" Value="0" />
                                </Items>--%>
                         </telerik:RadComboBox>

Code Behind:

Protected Sub RadComboBox_Project_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadComboBox_Project.DataBound
    Dim combo As RadComboBox = DirectCast(sender, RadComboBox)
    If combo.Items.Count > 1 Then
        combo.Items.Insert(0, New RadComboBoxItem("Select a Project", String.Empty))
    End If
End Sub

but it display a empty row in the combobox, how to remove it ? thanks



1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 01 Jul 2013, 05:45 AM
Hello Joe,

The observed blank row is actually the SelectedItem ("Select a Project"). Please try to explicitly call the DataBind method on the newly created RadComboBoxItem, in order to overcome the problematic behavior. Please consider the following implementation:
Protected Sub RadComboBox_Project_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadComboBox_Project.DataBound
       Dim combo As RadComboBox = DirectCast(sender, RadComboBox)
       If combo.Items.Count > 1 Then
           Dim item As RadComboBoxItem = New RadComboBoxItem
           item.Text = "Select a Project"
           RadComboBox_Project.Items.Insert(0, item)
           item.DataBind()
       End If
   End Sub


Regards,
Nencho
Telerik
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 the blog feed now.
Tags
ComboBox
Asked by
Joe
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or