Dinamically loaded Radcombobox does not show EmptyMessage

8 posts, 0 answers
  1. Alexandre
    Alexandre avatar
    7 posts
    Member since:
    Jun 2013

    Posted 31 Jul 2013 Link to this post

    Hi,

    I have a Radcombobox which is dinamically loaded as below:

    private void LoadFilters()
            {
                ControladorInternacao controladorInternacao = new ControladorInternacao();
                List<InternacaoSetorDTO> listaSetores = controladorInternacao.ListarTodosSetores(AmbienteConexao.Usuario().Cnes);
                List<RadComboBoxItem> listaTodosSetores = new List<RadComboBoxItem>();
                foreach (InternacaoSetorDTO item in listaSetores)
                {
                    listaTodosSetores.Add(new RadComboBoxItem(item.NomeSetor, item.CodInternacaoSetor.ToString()));
                }
     
                rcbFiltroSetor.DataSource = listaTodosSetores;
                rcbFiltroSetor.DataValueField = "Value";
                rcbFiltroSetor.DataTextField = "Text";
                rcbFiltroSetor.DataBind();
            }



    And it's not showing the EmptyMessage. Instead it's showing directly the items from the datasource.

    How can i  show a ".: Choose one :." item or make it show the EmptyMessage?

  2. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 31 Jul 2013 Link to this post

    Hello,

    Please try the below implementation

    1) Set the AppendDataBoundItems property of the combobox to True

    2) Add the custom item using  the DataBound event of combobox like given below
    protected void RadComboBox5_DataBound(object sender, EventArgs e)
       {
           var combo = (RadComboBox)sender;
           combo.Items.Insert(0, new RadComboBoxItem(".: Choose one :.", string.Empty));
       }

    PS:  We are not using ItemDatabound event here, instead we are using DataBound event of RadCombobox

    Thanks,
    A2H
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alexandre
    Alexandre avatar
    7 posts
    Member since:
    Jun 2013

    Posted 31 Jul 2013 Link to this post

    But what if i'd like to show the EmptyMessage instead of adding an "empty item" ?
  5. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 31 Jul 2013 Link to this post

    Hello,

    Please change the DataBound method like shown below to add a Empty message instead of Empty item

    protected void RadComboBox5_DataBound(object sender, EventArgs e)
      {
          var combo = (RadComboBox)sender;
          combo.EmptyMessage = "Please Select a Value";
      }


    Thanks,
    A2H
  6. Alexandre
    Alexandre avatar
    7 posts
    Member since:
    Jun 2013

    Posted 03 Aug 2013 Link to this post

    Thanks, but it didn't work.
    Any other solutions ? 
  7. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 03 Aug 2013 Link to this post

    Hello,
    Please find the code which I tried and and it works fine at my end.

    ASPX:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
     
            <telerik:RadComboBox ID="RadComboBox1" runat="server"
                ondatabound="RadComboBox1_DataBound">
            </telerik:RadComboBox>

    .CS Code
    protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadCombobox();
        }
        private void LoadCombobox()
        {
            List<RadComboBoxItem> listCombobox = new List<RadComboBoxItem>();
            List<TestClass> lstValues = new List<TestClass>();
            lstValues = this.GetListDetails();
            foreach (TestClass item in lstValues)
            {
                listCombobox.Add(new RadComboBoxItem(item.TestDescription.ToString(), item.TestID));
            }
            RadComboBox1.DataSource = listCombobox;
            RadComboBox1.DataValueField = "Value";
            RadComboBox1.DataTextField = "Text";
            RadComboBox1.DataBind();
        }
     
        public class TestClass
        {
            public String TestID { get; set; }
            public String TestDescription { get; set; }
        }
     
        public List<TestClass> GetListDetails()
        {
            List<TestClass> lstClass = new List<TestClass>();
     
            TestClass objtest = new TestClass();
            objtest.TestID = "1";
            objtest.TestDescription = "Value1";
            lstClass.Add(objtest);
     
            TestClass objtest1 = new TestClass();
            objtest1.TestID = "2";
            objtest1.TestDescription ="Value2";
            lstClass.Add(objtest1);
     
            return lstClass;
             
        }
     
        protected void RadComboBox1_DataBound(object sender, EventArgs e)
        {
            var combo = (RadComboBox)sender;
            combo.EmptyMessage = "Please Select a Value";
        }

    Unfortunately I couldn't find the reason why it’s not working for you.
    Can you please provide more details.

    Thanks,
    A2H

  8. Logan
    Logan avatar
    23 posts
    Member since:
    Jan 2012

    Posted 24 Apr 2015 in reply to Alexandre Link to this post

    I have this same problem too.  the empty message isn't there until you click the drop down at least once.
  9. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 29 Apr 2015 Link to this post

    Hello Logan,

    Please specify which version of our controls are you currently using. Such bug existed in previous version of our controls, when the CheckBoxes feature of the RadComboBox is enabled.

    Regards,
    Nencho
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017