How to remove a blank row in combobox

2 posts, 0 answers
  1. Joe
    Joe avatar
    57 posts
    Member since:
    Mar 2013

    Posted 25 Jun 2013 Link to this post

    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



  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 01 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top