简体   繁体   English

数据绑定:“System.Web.SiteMapNode”不包含属性

[英]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.

相关问题 System.Web.HttpException:&#39;数据绑定:&#39;System.Web.UI.WebControls.SqlDataSource&#39;不包含名称为&#39;Name&#39;的属性。 - System.Web.HttpException: 'DataBinding: 'System.Web.UI.WebControls.SqlDataSource' does not contain a property with the name 'Name'.' 数据绑定:“ System.Web.UI.Pair”不包含名称为“ First”的属性 - DataBinding: 'System.Web.UI.Pair' does not contain a property with the name 'First' DataBinding不包含属性 - DataBinding does not contain a property DataBinding:&#39;System.String&#39;不包含名为&#39;Text&#39;的属性 - DataBinding: 'System.String' does not contain a property with the name 'Text' 数据绑定:“ System.Data.DataRowView”不包含名称为“任务列表”的属性 - DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Tasklist' 数据绑定:“ System.Char”不包含名称为“ xxxxx”的属性 - DataBinding: 'System.Char' does not contain a property with the name 'xxxxx' 数据绑定:“ System.Data.DataRowView”不包含名称为“ DocID”的属性 - DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'DocID' DataBinding:“ System.Data.DataRowView”不包含名称为“ image”的属性 - DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'image' 数据绑定:“ System.Data.DataRow”不包含名称为“标题”的属性 - DataBinding: 'System.Data.DataRow' does not contain a property with the name 'Caption' 数据绑定:“ System.String”不包含名称为“ Name”的属性 - DataBinding: 'System.String' does not contain a property with the name 'Name'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM