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

[Solved] TreeView node html attributes does NOT take affect when the node Uri set

4 Answers 97 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
propel studio
Top achievements
Rank 1
propel studio asked on 02 Sep 2010, 02:34 AM

Hi,

I am using Q2 2010 release.

Here is the problem – if a node has link set (has <a class=”t-link…”> </a> inside <li class=”t-item…”> </li>.

The node html attributes will not take affect on the node text.  Below is an example:

With item.Uri set: (Note: the node text "A Node" does NOT show blue.

.ItemDataBound((item, p) =>
{
   item.Text = p.Name;
   item.Url = "#";
   item.HtmlAttributes.Add("style", "color:blue");            
})
It renders as:
......
 <li class="t-item" style="color: blue">  
   <div class="t-mid">
    <a class="t-link t-in" href="#">A Node</a></div>
 </li>
......

Without item.Uri set:  ( Note: the node text “A Node” DOES show blue.)

.ItemDataBound((item, p) =>
{
   item.Text = p.Name;
   //item.Url = "#";
   item.HtmlAttributes.Add("style", "color:blue");            
})
 
It renders as:
.......
<li class="t-item" style="color: blue">
   <div class="t-mid">
    <span class="t-in"> A Node </span></div>
</li>
.......

Do I miss something?

Thanks,

Propel studio

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Sep 2010, 07:46 AM
Hello propel studio,

 The <a> tag does not inherit "color" from its parent element. This is the reason why you are not seeing the color applied. Use the LinkHtmlAttributes in order to set the html attributes of the link.

Greetings,
Atanas Korchev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
propel studio
Top achievements
Rank 1
answered on 03 Sep 2010, 11:39 PM

Atanas,

Thank you for reply.

You are right. I should use LinkHtmlAttributes to set link html attributes.

I am experiencing another issue on adding class attribute, here is the example:

If the original link shows <a class="t-link t-in" href="#">A Node</a>.  After I use item.HtmlAttributes.Add("class", "xyz") to add class. The rendered result becomes <a class="t-link xyz " href="#">A Node</a>. Please notice, the new class


Do I still miss something?


Also, do you have example on how to add MVC Ajax.ActionLink(...) to a tree node.


Thank you!

Propel studio

0
Hristo Germanov
Telerik team
answered on 06 Sep 2010, 02:12 PM
Hello propel studio,

Thank you for reporting this issue.

I confirm that it is a bug, which will be fixed with next official release of Telerik Components for ASP.NET MVC.

Please, replace the existing code

IHtmlNode tag = new HtmlTag(isNavigatable ? "a" : "span");
  
tag.PrependClass("t-in")
   .ToggleClass(UIPrimitives.DisabledState, !item.Enabled)
   .ToggleClass(UIPrimitives.SelectedState, item.Enabled && item.Selected);
   
   if (isNavigatable)
   {
       if (item.Enabled)
       {
           tag.Attribute("href", url);
           }
                tag.Attributes(item.LinkHtmlAttributes)
                   .PrependClass(UIPrimitives.Link);
           }
           tag.Attributes(item.LinkHtmlAttributes)
                   .PrependClass(UIPrimitives.Link);
       }
   }
....

with this
 
IHtmlNode tag = new HtmlTag(isNavigatable ? "a" : "span")
               .Attributes(item.LinkHtmlAttributes);
 
tag.PrependClass("t-in")
   .ToggleClass(UIPrimitives.DisabledState, !item.Enabled)
   .ToggleClass(UIPrimitives.SelectedState, item.Enabled && item.Selected);
 
   if (isNavigatable)
   {
       if (item.Enabled)
       {
           tag.Attribute("href", url);
       }
       tag.PrependClass(UIPrimitives.Link);
   }
....

in TreeViewHtmlBuilder.cs and rebuild the source project. Make sure the build configuration is set to Release MVC2 NET35 if you are using ASP.NET MVC 2.

I have updated your Telerik points.

Sincerely yours,
Hristo Germanov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
tomas
Top achievements
Rank 1
answered on 28 Feb 2011, 01:29 PM
Hello Telerik team,

I have downloaded yours new version of Telerik Components for ASP.NET MVC but i cant change treeview text color.Is other way how can change text color in treeview because rebuild yours source code in all newest version is not good way.

Thanks for reply

Best regards

Tomas
Tags
TreeView
Asked by
propel studio
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
propel studio
Top achievements
Rank 1
Hristo Germanov
Telerik team
tomas
Top achievements
Rank 1
Share this question
or