How to create a RadComboBox that is initially not selecting any items?

800 views Asked by At

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();
      }
    }
  }
}
1

There are 1 answers

3
AustinS90 On

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