News ItemTemplate Index

Posted by Community Admin on 03-Aug-2018 17:26

News ItemTemplate Index

All Replies

Posted by Community Admin on 21-Jan-2011 00:00

Hi,

I am trying to define my own template of the news list and I must know what is the last element to give him a diferent style.
I have tried to acomplish this using the folowing code

<telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
    <LayoutTemplate>
        <div class="col-second-box-bg">
        <h3 class="bg txt-shadow">News</h3>
        <ul >
            <asp:PlaceHolder ID="ItemsContainer" runat="server" />
        </ul>
        </div>
    </LayoutTemplate>
    <ItemTemplate>
            <li  class='<%# ((ListViewDataItem)Container).DisplayIndex  == 1 ? "last" : "" %>'>
            <h5 >
                <sf:DetailsViewHyperLink ID="DetailsViewHyperLink1" TextDataField="Title" ToolTipDataField="Description" runat="server" />
            </h5>  ...

And the result is an error when using:
 <%# ((ListViewDataItem)Container).DisplayIndex  == 1 ? "last" : "" %>

How can I accomplish this without rewrite a new NewsList Widget?

Thanks in advance.

Posted by Community Admin on 21-Jan-2011 00:00

Hi Paulo,

The problem here is that our template parser cannot parse the value you use. Sitefinity uses its own parser for parsing embedded resources. Compared to the ASP.NET parser, this parser has limited capabilities for parsing C# code. In one of the future updates it will be added the option of using the ASP.NET template parser for similar scenario like yours.

The solution requires to remove this code from your .ascx file and then to move it to a custom class that inherits from MasterListView and its InitializeControls method where you will be able to access NewsList from the view container

To register your custom MasterListView,open App_Data/Sitefinity/Configuration/NewsConfig.config and register the new MasterListView.


<contentViewControls>
        <contentViewControl definitionName="NewsFrontend">
            <views>
                <view viewName="NewsFrontendListCustom" ViewType="Telerik.Sitefinity.Samples.Class2, Telerik.Sitefinity.Samples" />
            </views>
        </contentViewControl>
    </contentViewControls>

Finally you have to set the custom MasterListView inside  Home > ControlDefinition > Views > NewsFrontendList of the NewsView control

All the best,

Ivan Dimitrov
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

This thread is closed