2

I face the following problem when i use RadComboBox :

    ddl_contactList.Items.Clear();
    ddl_contactList.DataSource = ContactList.GetContactListsByDep(year, main_code);
    ddl_contactList.DataTextField = "list_desc";
    ddl_contactList.DataValueField = "list_code";
    ddl_contactList.DataBind();
    ddl_contactList.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("NewList", "-1"));
    ddl_contactList.SelectedIndex = 0;

  <telerik:RadComboBox ID="ddl_contactList" runat="server" AutoPostBack="True" CausesValidation="False"
            CollapseDelay="0" Culture="ar-EG" ExpandDelay="0" Filter="StartsWith" ItemsPerRequest="10"
            MarkFirstMatch="true" Skin="Outlook" EnableAutomaticLoadOnDemand="True" EmptyMessage="-List name-"
            ShowMoreResultsBox="True" 
            onselectedindexchanged="ddl_contactList_SelectedIndexChanged" AppendDataBoundItems ="true">
    </telerik:RadComboBox>

always the number of items in the combo box is 1 !!! although the datasource contains many items so when i try to get the selected value for any item in any time, i always get -1 !!

How to get the correct selectedvalue ?

Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

2 Answers2

1

Add the NewList item before databinding and add the following attribute to RadComboBox.

Setting AppendDataBoundItems to True preserves the items that are already present in RadComboBox. This lets you bind RadComboBox to multiple data sources or use both unbound and bound modes.

Then add the datasource to the control.

ddl_contactList.Items.Clear();
ddl_contactList.Items.Insert(0, new Telerik.Web.UI.RadComboBoxItem("NewList", "-1"));
ddl_contactList.SelectedIndex = 0;


ddl_contactList.DataSource = ContactList.GetContactListsByDep(year, main_code);
ddl_contactList.DataTextField = "list_desc";
ddl_contactList.DataValueField = "list_code";
ddl_contactList.DataBind();
Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
1

How about adding them individually instead of binding.

var items = ContactList.GetContactListsByDep(year, main_code); 

foreach(var item in items)
{
   ddl_contactList.Items.Add(new RadComboBoxItem(item.list_desc, item.list_code));
}

ddl_contactList.Items.Insert(0, new RadComboBoxItem("NewList", "-1")); 
ddl_contactList.SelectedIndex = 0; 
Win
  • 61,100
  • 13
  • 102
  • 181
  • I did that , and it works but when there are many items the `comcbo box` becomes so heavy onloading !! – Anyname Donotcare Jun 22 '12 at 08:17
  • You might want to consider using OnItemsRequested. It loads combobox items via ajax when user starts typing inside the combobox. http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx – Win Jun 22 '12 at 14:01