Why is This RadComboBox Not showing My Selection

481 views Asked by At

I have this Telerik ComboBox

                  <telerik:RadComboBox 
            runat="server" 
            ID="ddlSpecialist"
            AutoPostBack="True"            
            EnableLoadOnDemand="True"
            HighlightTemplatedItems="True"           
            OnClientItemsRequested="UpdateEmployeesCountField" 
            EnableItemCaching="True" 
            DropDownWidth="200px"
            OnItemsRequested="ddlSpecialist_ItemsRequested"  
            onclientblur="OnClientBlurHandler"                                                                                                 
            Width="75px"                                                                                                                    
          >

The dropdown works and shows me the data I am expected. But when I select one of the values the ComboBox selection does not show the selected EID. It changes and then shows this text as the selected item "Pirs2020.VW_EMP" instead of the EID number I expected. Pirs2020.VW_EMP is the name of Visual Studio project and the name of the View used to populate the ComboBox.

Here is the code I am using to populate the ComboBox:

protected void ddlSpecialist_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
    {
        using (PIRSXEntities db = new PIRSXEntities())
        {
            var allPersonnel = db.VW_EMP.OrderBy(a => a.EID);
            if (!String.IsNullOrEmpty(e.Text))
            {
                allPersonnel = db.VW_EMP.Where(i => i.EID.ToString().Contains(e.Text.Trim()))
                    .OrderBy(i => i.EID);
            }
            IQueryable<VW_EMP> personnel = allPersonnel.Skip(e.NumberOfItems).Take(10);
            ddlSpecialist.DataSource = personnel.Distinct().ToList();
            ddlSpecialist.DataBind();
            int endOffset = e.NumberOfItems + personnel.Count();
            int totalCount = allPersonnel.Count();

            if (endOffset == totalCount)
                e.EndOfItems = true;

            e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>",
                endOffset, totalCount);
        }
    }

Why am I getting this strange item showing as my selected value?

1

There are 1 answers

0
Perry On

I was able to track down the problem. The issue was I failed to set the values for the DataText and Data Value. I added the code below between the setting of the dataSource value and the Data Bind command. So it looks like this

 ddlSpecialist.DataSource = personnel.Distinct().ToList();
            ddlSpecialist.DataTextField = "Full_Name";
            ddlSpecialist.DataValueField = "EID";
            ddlSpecialist.DataBind();