How to make a part of the radcomboboxitem text bold ?

9 posts, 0 answers
  1. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2011 Link to this post


    Hi,

    Iam using a radcombo box to populate a list of ids and corresponding names (first name + last name).
    How can I make Firstname bold ?

    DataValueField

     

    ="Id"

     


    DataTextField

     

    ="Name"

    Your help is very much appreciated.

     

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2011 Link to this post

    Hello Bhanu,

    Try the following approach to achieve your requirement.

    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
            RadComboBox1.DataSource = CreateDataSource();
            RadComboBox1.DataTextField = "Name";
            RadComboBox1.DataValueField = "ID";
            RadComboBox1.DataBind(); 
        }
        protected DataTable CreateDataSource()
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
            dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
     
            DataRow dr = dataTable.NewRow();
            dr["ID"] = "1";
            dr["Name"] = "<b>FirstName1</b>LastName1";
            dataTable.Rows.Add(dr);
     
            DataRow dr2 = dataTable.NewRow();
            dr2["ID"] = "2";
            dr2["Name"] = "<b>FirstName2</b>LastName2";
            dataTable.Rows.Add(dr2);
     
            return dataTable;
        }
    }

    Thanks,
    Shinu.
  3. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 14 Jul 2011 Link to this post

    Thanks for the quick response. Please see the attached output for the code. First name is not displayed in bold.
    Please help. Here is the code I have used.

    <telerik:RadComboBox ID="RadComboBox1" AutoPostBack="true" runat="server"
           Height = "120px" Width = "500px">
           </telerik:RadComboBox>
      
      
      
      
    protected void Page_Load(object sender, EventArgs e)
        {
          RadComboBox1.DataSource = CreateDataSource();
          RadComboBox1.DataTextField = "Name";
          RadComboBox1.DataValueField = "ID";
          RadComboBox1.DataBind(); 
        }
      
        protected DataTable CreateDataSource()
        {
          DataTable dataTable = new DataTable();
          dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
          dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
      
          DataRow dr = dataTable.NewRow();
          dr["ID"] = "1";
          dr["Name"] = "<b>FirstName1</b>LastName1";
          dataTable.Rows.Add(dr);
      
          DataRow dr2 = dataTable.NewRow();
          dr2["ID"] = "2";
          dr2["Name"] = "<b>FirstName2</b>LastName2";
          dataTable.Rows.Add(dr2);
      
          return dataTable;
        }
  4. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 15 Jul 2011 Link to this post

    Any update on this please ?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Jul 2011 Link to this post

    Hello Bhanu,

    Change the mark up as follows.
    aspx:
    <telerik:RadComboBox runat="server" ID="RadComboBox1" AppendDataBoundItems="true" >
        <Items>
            <telerik:RadComboBoxItem Text="Select" Value="-1" />
        </Items>
        <ItemTemplate>
             <%# Eval("Name") %>
          </ItemTemplate>
    </telerik:RadComboBox>

    Thanks,
    Shinu.
  6. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 15 Jul 2011 Link to this post

    Thanks. I followed your instructions. The dropdown is populated with bold text. But when the cursor is placed on any of the listed items those are not highlighted / selectable. When we click on any the items we got the attached error.
    Please provide the solution.

    Thanks
    Bhanu.
  7. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 15 Jul 2011 Link to this post

    Also please note that this RadComboBox is part of Site.Master page, not in .aspx page.
    Please provide your update at the earliest. Thank you.
  8. Bhanu
    Bhanu avatar
    41 posts
    Member since:
    Jul 2010

    Posted 18 Jul 2011 Link to this post

    Any update please.
  9. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 19 Jul 2011 Link to this post

    Hello Bhanu,

    One way to go around the error that you encounter is to turn off the request validation which is done at page level:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default14.aspx.cs" Inherits="Default14" ValidateRequest="false" %>

    However, you should be aware that allowing the users to type html in the inputs is not safe nor secure. So you should be careful. Please take a look at the following forum thread where the same issue is being discussed.

    Best wishes,
    Kate
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top