从<%#%>

时间:2017-04-05 07:57:11

标签: kentico

enter image description here

<cms:CMSRepeater ID="rptTopic" runat="server" SelectOnlyPublished="true" OrderBy="NodeLevel,NodeOrder" ClassNames='<%# CLASS_NAME %>' Path='<%# Path %>'>

enter image description here

CLASS_NAMEPath的值是在后端预定义的。但我仍然收到错误。

我的代码有什么问题吗?

以下是代码的全部内容。

    <cms:CMSRepeater ID="CMSRepeater1" runat="server" SelectOnlyPublished="true" OrderBy="NodeLevel,NodeOrder" ClassNames='<%# CLASS_NAME %>' Path='<%# Path %>'>
        <ItemTemplate>
            <div class="col-md-3">
                <div class="panel panel-default">
                    <asp:Image ID="imgTopic" runat="server" Height="200px" Width="100%" ImageUrl='<%# Eval("BackgroundImage") %>' />
                    <h4><%# Eval("Title") %></h4>
                    <p><%# Eval("Descriptions") %></p>
                    <a class="btn" href='<%# Eval("UrlLink") %>'>
                        <%# Eval("UrlText") %>
                    </a>
                </div>
            </div>
        </ItemTemplate>
    </cms:CMSRepeater>

这是我得到的例外:

Message: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'BackgroundImage'.

Exception type: System.Web.HttpException
Stack trace: 
at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
at System.Web.UI.DataBinder.Eval(Object container, String[] expressionParts)
at System.Web.UI.DataBinder.Eval(Object container, String expression)
at System.Web.UI.TemplateControl.Eval(String expression)
at CMS.Base.Web.UI.AbstractUserControl.Eval(String column)
at ASP.inteksoft_webparts_content_topiclisting_ascx.__DataBinding__control3(Object sender, EventArgs e) in C:\Users\yjseow\Desktop\inteksoft svn\trunk\MOT\MOT.Website\Website\CMS\Inteksoft\WebParts\Content\TopicListing.ascx:line 9
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem)
at System.Web.UI.WebControls.Repeater.AddDataItemsIntoItemsArray(IEnumerable dataSource, Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.PostGetDataAction(IEnumerable dataSource)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at CMS.DocumentEngine.Web.UI.BasicRepeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.Repeater.DataBind()
at CMS.DocumentEngine.Web.UI.BasicRepeater.DataBind()
at CMS.DocumentEngine.Web.UI.CMSRepeater.DataBind()
at CMS.DocumentEngine.Web.UI.CMSRepeater.ReloadDataInternal(Boolean forceReload)
at CMS.DocumentEngine.Web.UI.CMSRepeater.<>c__DisplayClass3.b__2()
at CMS.Base.Web.UI.ControlsExtensions.CallHandled(Control ctrl, Action func)

基于我得到的异常,在我检查了我的列字段名称是正确的之后,我怀疑我无法指向正确的类名。

ClassNames='<%# CLASS_NAME %>' Path='<%# Path %>'>切换到ClassNames="CMS.Topic" Path="/Shared/Topic/%"后,一切顺利。

我正在尝试让ClassNamesPath成为动态可控制的。

3 个答案:

答案 0 :(得分:2)

如果CLASS_NAME和Path Path是代码隐藏文件的属性,您可以尝试在页面加载的代码隐藏文件中使用它们初始化转发器。与rptTopic.ClassNames = CLASS_NAME;rptTopic.Path = Path一样。或者使用<%=...%>代替<%#...%>

<cms:CMSRepeater ID="CMSRepeater1" runat="server" SelectOnlyPublished="true" OrderBy="NodeLevel,NodeOrder" ClassNames='<%= CLASS_NAME %>' Path='<%= Path %>'/>

答案 1 :(得分:0)

下次从事件日志添加日志。 尝试:

<cms:CMSRepeater ID="rptTopic" runat="server" SelectOnlyPublished="true" OrderBy="NodeLevel,NodeOrder" ClassNames='<%# CLASS_NAME %>' Path='<%# Path %>' />

注意在结束括号之前斜杠char。

编辑: 尝试使用

<%# Eval("ClassName")%>

答案 2 :(得分:0)

由于注释不能包含代码标记,因此如果您需要设置Repeater的值超过内联标记中的值,则可以执行以下操作:

<cms:CMSRepeater ID="rptTopic" runat="server" SelectOnlyPublished="true" OrderBy="NodeLevel,NodeOrder" />
<script runat="server">
    protected override void OnInit(EventArgs e)
    {
        rptTopic.ClassName = CMS.Helpers.ValidationHelper.GetString(Eval("ClassName"),"");
        rptTopic.Path = CMS.Helpers.ValidationHelper.GetString(Eval("Path"),""); 
    }
</script>