[英]DataBinding: 'System.Web.SiteMapNode' does not contain a property
I want to add glyphicons to my custom built menu that I built using an <asp:Repeater>
and a web.sitemap
file as a data source.我想将字形添加到我使用<asp:Repeater>
和web.sitemap
文件作为数据源构建的自定义构建菜单中。
Here is what I've tried:这是我尝试过的:
<ul class="nav navbar-nav">
<asp:Repeater runat="server" ID="rptMenu" DataSourceID="smdsMain">
<ItemTemplate>
<li>
<a runat="server" href='<%# Eval("url") %>'>
<span class='glyphicon glyphicon-<%# Eval("glyphicon") %>'></span>
<%# Eval("title") %>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<asp:SiteMapDataSource ID="smdsMain" runat="server" ShowStartingNode="false" SiteMapProvider="XmlSiteMapProvider" />
And here's an example of a node in my web.sitemap
:这是我的web.sitemap
中的节点示例:
<siteMapNode url="~/Secure/Home/Default" title="Home" description="Home" glyphicon="home" />
Here is the error I get.这是我得到的错误。
System.Web.HttpException: DataBinding: 'System.Web.SiteMapNode' does not contain a property with the name 'glyphicon'. System.Web.HttpException: DataBinding: 'System.Web.SiteMapNode' 不包含名为 'glyphicon' 的属性。
I everything else works fine without the glyphicon implementation.如果没有 glyphicon 实现,我其他一切都可以正常工作。
I know it is possible to have a custom attribute in your sitemap nodes because someone implemented it in this Stack Overflow post .我知道您的站点地图节点中可能有一个自定义属性,因为有人在这篇Stack Overflow 帖子中实现了它。
So I must be doing something wrong in my customer implementation.所以我一定在我的客户实施中做错了什么。 What is the correct way to implement this?实现这一点的正确方法是什么?
After some research I found that you can access custom attributes in this way:经过一番研究,我发现您可以通过这种方式访问自定义属性:
<%# Eval("[attributeName]") %>
Using that knowledge I have implemented into my code like this to get it working:使用这些知识,我已经在我的代码中实现了这样的功能:
<ul class="nav navbar-nav">
<asp:Repeater runat="server" ID="rptMenu" DataSourceID="smdsMain">
<ItemTemplate>
<li>
<a runat="server" href='<%# Eval("url") %>'>
<span class='glyphicon glyphicon-<%# Eval("[glyphicon]") %>'></span>
<%# Eval("title") %>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<asp:SiteMapDataSource ID="smdsMain" runat="server" ShowStartingNode="false" SiteMapProvider="XmlSiteMapProvider" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.