This is a migrated thread and some comments may be shown as answers.

mvc 5 c# html color individual characters of string

3 Answers 184 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Arun
Top achievements
Rank 1
Arun asked on 30 Nov 2015, 07:47 PM
In c# , I am trying to set font for individual characters of string.

Below is my code that I use with Kendo Grid to display tree node text which displays some count in brackets. 

Example Customer1(**20**). Here I want to bold and color count.

     Name = EmpDb.Description + ((EmpDb.Cust.Count() > 0) ? "(" : "") +
                                  ((EmpDb.Cust.Count() > 0) ? EmpDb.Cust.Count().ToString() : "") +
                                 ((EmpDb.Cust.Count() > 0) ? ")" : "")

I tried below to bold, but it did not work and I got html tags in string. 

     Name = EmpDb.Description + ((EmpDb.Cust.Count() > 0) ? "(<b>" : "") +
                                  ((EmpDb.Cust.Count() > 0) ? EmpDb.Cust.Count().ToString() : "") +
                                 ((EmpDb.Cust.Count() > 0) ? "</b>)" : "")

Thank you.

3 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 02 Dec 2015, 01:37 PM
Hi Arun,

My understanding is that you want to display HTML markup inside the TreeView items, and the widget is server-bound. In this case, the easiest thing to do is disable TreeView item encoding.

@(Html.Kendo().TreeView()
    .Name("treeview")
    .Items(treeview =>
    {
        treeview.Add().Text("<b>Text</b>").Encoded(false);
 
    })
)


In case your scenario is different, please provide more information and clarify what is the relationship between the Grid and the TreeView, and how is the TreeView related to the provided server code.

Regards,
Dimiter Topalov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 03 Dec 2015, 01:50 AM

Thanks for reply.

 Actually I am doing similar to example at http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/treeview/ajax-binding

 So in the example exactly similar to above, for my Jason result, Name value is retrevied as

 Name = EmpDb.Description + ((EmpDb.Dept.Count() > 0) ? " (" : "") +

                                  ((EmpDb.Dept.Count() > 0) ? EmpDb.Dept.Count().ToString() : "") +
                                 ((EmpDb.Dept.Count() > 0) ? ")" : "")

 So my question is for above how can i set  font for value between bracket.

for example If I have  treeview node text as

 Sam (5)

then I want value 5 to be bold and in color.

 

Thank You.

0
Dimiter Topalov
Telerik team
answered on 07 Dec 2015, 08:07 AM
Hello Arun,

You can try to wrap the value in the brackets in a <strong> tag like in the following example:

Name = EmpDb.Description + ((EmpDb.Dept.Count() > 0) ? "(<strong>" : "") +
        ((EmpDb.Dept.Count() > 0) ?
    EmpDb.Dept.Count().ToString() :
"") +
         ((EmpDb.Dept.Count() > 0) ? "</strong>)" : "")

And then disable the encoding for the corresponding TreeView item:

@(Html.Kendo().TreeView()
    .Name("treeview")
    .Items(treeview =>
    {
        treeview.Add().Text("<b>Text</b>").Encoded(false);
 
    })
)

If this doesn't work, please provide us with a more comprehensive sample of the code, which shows the TreeView and model setup.

Regards,
Dimiter Topalov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
Arun
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Arun
Top achievements
Rank 1
Share this question
or