Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 515373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:37:17+00:00 2026-05-13T07:37:17+00:00

How do I stick HTML formatting into a String object in C#? Here’s what

  • 0

How do I stick HTML formatting into a String object in C#?

Here’s what I have:

c.DepartmentAbbr.ToString() + " - (" + c.DepartmentName.ToString() + ")"

where c.DepartmentAbbr.ToString() and c.DepartmentName.ToString() are both fields being selected from a data context using LINQ.

Here’s what I essentially want:

"<b>" + c.DepartmentAbbr.ToString() + "</b> - (" + c.DepartmentName.ToString() + ")"

so that the first word shows up in bold. The above just shows the literal text with the bold tags and everything. I assume I will need to use String.Format but I can’t quite find a good example that helps me know how to use it to do what I want.

Update

Here are a few more details that I didn’t think were important but I think by now they must be.

Here is the control I’m using. ASPX code:

 <telerik:RadComboBox ID="rcbDepartments" runat="server" AppendDataBoundItems="True"
        AutoPostBack="true" NoWrap="true" Width="250px">
        <Items>
            <telerik:RadComboBoxItem Text="All Departments" Value="-1" />
        </Items>
    </telerik:RadComboBox>

And I’m adding items to this control using LINQ in C#:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var abbr = from c in DB.Departments
                   where c.DepartmentAbbr != "BInst"
                   select c;

        foreach (var c in abbr)
        {
            String s = String.Format("{0} - ({1})", c.DepartmentAbbr, c.DepartmentName);
            rcbDepartments.Items.Add(new RadComboBoxItem(s, c.DepartmentID.ToString()));
        }
    }
}

The RadComboBoxItem object accepts either (), (String text), or (String text, String value), and I am using the latter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:37:18+00:00Added an answer on May 13, 2026 at 7:37 am

    As I’ve researched more and more I’ve pretty much come to the conclusion that what I want to do is not possible. I’m using a RadComboBox to stick the items into, but I’m having to do some funcky stuff with LINQ on the server side such that I have to stick the items into the combo box using the Items.Add method which only accepts System.String. Thank you all for your help and comments but I think I’m just going to have to make do with what I have in this case.

    Here are a few more details that I didn’t think were important but I think by now they must be.

    Here is the control I’m using.
    ASPX code:

    And I’m adding items to this control using LINQ in C#:
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    var abbr = from c in DB.Departments
    where c.DepartmentAbbr != “BInst”
    select c;

            foreach (var c in abbr)
            {
                String s = String.Format("{0} - ({1})", c.DepartmentAbbr, c.DepartmentName);
                rcbDepartments.Items.Add(new RadComboBoxItem(s, c.DepartmentID.ToString()));
            }
        }
    }
    

    The RadComboBoxItem object accepts either (), (String text), or (String text, String value), and I am using the latter. I am pretty sure by now that due to the restrictions on the RadComboBoxItem only accepting Strings that I can not do HTML formatting on the items without using the Item Template tags in ASPX. Unfortunately for my situation I can not do this because that was already causing some other problems for me which I why I’m doing what I am currently trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 301k
  • Answers 301k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is the release necessary? Aren't all properties already handled automatically?… May 13, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer Name your URLs by adding another item to the tuple:… May 13, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer Here I found possible answer to your question. I think… May 13, 2026 at 8:08 pm

Related Questions

I have to keep the formatting the exact same way that I got this
I have a JavaScript slideshow that pre-loads images out of a MySQL database and
I am wondering how do I first detect if Javascript is enabled/disabled. Disabling javascript
How do I tell the Zend_Form that I want an element (and it's ID-label,
I have used html and body attributes to have a gradient background and a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.