Alternative Text in treeview control in asp.net

江枫思渺然 提交于 2019-12-13 02:56:39

问题


I am looking for a solution. My treeview control contains the menuitems for my web application and its populated from a sitemap and it's working fine. Now I need to add alternative text to that menu items created. How can I add alternative text to these treeview items.

My treeview code is like below

protected void MainMenu_NodeDataBound(object sender, TreeNodeEventArgs e)
{
    var siteMapnode = e.Node.DataItem as SiteMapNode;
    e.Node.Value = siteMapnode.Url;
    e.Node.NavigateUrl = string.Empty;
    e.Node.SelectAction = (siteMapnode.Url != String.Empty) ? TreeNodeSelectAction.Select : TreeNodeSelectAction.None;
    e.Node.PopulateOnDemand = false;         
}

回答1:


Not really sure what you mean by 'alternative text' but you may be looking for the Tag property.

Example:

...

e.Node.Tag = "Alternative Text, whatever that means.";

...

You can set a Node's Tag property to whatever you want since it's type object, which I find pretty handy. Reference here.




回答2:


There is no alt. I believe what you want is title, which is set using the ToolTip attribute:

e.Node.ToolTip = "I provide useful info about the link."

Which will get rendered as:

<a href="yourlink.aspx" title="I provide useful info about the link.">Some Text</a>

alt is used to specify alternate text for elements when they can't be rendered (i.e. NOT anchor tags). Outside of IE, browsers will not use this to provide text that displays when the element is hovered.

From HTML Techniques for Web Content Accessibility Guidelines 1.0:

In addition to clear link text, content developers may specify a value of the "title" attribute that clearly and accurately describes the target of the link.

If more than one link on a page shares the same link text, all those links should point to the same resource. Such consistency will help page design as well as accessibility.

If two or more links refer to different targets but share the same link text, distinguish the links by specifying a different value for the "title" attribute of each A element.




回答3:


Alternate text in ASP.Net :

AlternateText="Your Text"


来源:https://stackoverflow.com/questions/21003874/alternative-text-in-treeview-control-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!