1

I have a RadComboBox on a page. How do I initiate it without any items being selected?

The following box contains two items, I have tried to use both ClearSelection() and SelectedIndex = -1, without any luck.

It still looks like this (having its first item selected).

First item selected

RadComboBoxTest.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadComboBoxTest.aspx.cs"
  Inherits="Foo.Bar.RadComboBoxTest" %>
<!DOCTYPE html>

<html>
<head runat="server">
  <title>test</title>
</head>
<body>
  <form runat="server">
    <asp:ScriptManager runat="server"/>
    <div>
      Items:<br/>
      <telerik:RadComboBox ID="cmbTest" DataValueField="id" 
          DataTextField="name" runat="server"/>
    </div>
  </form>
</body>
</html>

RadComboBoxTest.aspx.cs

using System;
{
  namespace Foo.Bar
  {
    public partial class RadComboBoxTest : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
        cmbTest.DataSource = new object[]
        {
          new { id =  23, name = "twentythree"},
          new { id =  24, name = "twentyfour"}
        };

        cmbTest.DataBind();
        cmbTest.ClearSelection();
      }
    }
  }
}
Anders Lindén
  • 6,839
  • 11
  • 56
  • 109

1 Answers1

0

Have you tried creating a new object, with the id of 0, and name = empty string (" "), and setting the default value to 0

Note: Comment below with Telerik link explains this much better

Aaron. S
  • 467
  • 4
  • 12
AustinS90
  • 153
  • 6
  • Thanks, but I do not want an empty item. – Anders Lindén Sep 12 '17 at 06:06
  • 1
    You are going to have to add an empty row, that does nothing, it is also what is suggested by Telerik it self http://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/how-to/insert-a-default-item-when-databinding-radcombobox – AustinS90 Sep 15 '17 at 20:17
  • You can do this in plain html like https://jsfiddle.net/p5xpgckz/ so I expect it to be possible with a telerik:RadComboBox as well. – Anders Lindén Sep 16 '17 at 08:23