DropDownList HTML items text not working

3 posts, 1 answers
  1. Leandro
    Leandro avatar
    48 posts
    Member since:
    Jul 2015

    Posted 24 Aug 2018 Link to this post

    Hey guys, I've got a problem, the selected item text just don't work with html formatted text. Any help? I'm using telerik 2015
  2. Leandro
    Leandro avatar
    48 posts
    Member since:
    Jul 2015

    Posted 24 Aug 2018 Link to this post

    Ok, I managed to solve it just by setting the style to dropdownlist, I don't need it to be dropdown anyway. But the problem stills exists.
  3. Answer
    Hristo
    Admin
    Hristo avatar
    1519 posts

    Posted 28 Aug 2018 Link to this post

    Hello Leonardo,

    Thank you for writing.

    I am not sure how you ended up with the formatted text in the editor of the RadDropDownList control. This editor actually extends the standard Microsoft text box and it cannot be used with HTML-like formatted text. You can try handling the VisualListItemFormatting event of the control and only format the item displayed in the list when it is open: 
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
     
            this.radDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
            this.radDropDownList1.VisualListItemFormatting += RadDropDownList1_VisualListItemFormatting;
        }
     
        private void RadDropDownList1_VisualListItemFormatting(object sender, Telerik.WinControls.UI.VisualItemFormattingEventArgs args)
        {
            string text = string.Format("<html><strong>{0}</strong></html>", args.VisualItem.Text);
            args.VisualItem.Text = text;
        }
    }

    I hope this will help. Let me know if you have other questions.

    Regards,
    Hristo
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top