Convert News List to Dropdown - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Convert News List to Dropdown

  • Convert News List to Dropdown
  • I need to display a list of news items as a dropdown.  I am trying to create a news list template for use in the control when needed.  I do not really care if it is a dropdown or a combo box as long as it acts like a dropdown (is the combobox lockable to prevent typing?).  I know the dropdown can use templates, but I am getting something wrong (error parsing template).

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Comments.Web.UI.Frontend" TagPrefix="comments" %>
    <%@ Import Namespace="Telerik.Sitefinity.Web.UI" %>
    <%@ Import Namespace="Telerik.Sitefinity.Modules.Comments" %>
     
    <sf:SitefinityLabel id="title" runat="server" WrapperTagName="div" HideIfNoText="true" HideIfNoTextMode="Server" />
    <telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <LayoutTemplate>
          <telerik:RadDropDownList>
            <ItemTemplate>
              <sf:DetailsViewHyperLink ID="DetailsViewHyperLink1" TextDataField="Title" ToolTipDataField="Description" data-sf-field="Title" data-sf-ftype="ShortText" runat="server" />
            </ItemTemplate>
            <Items>
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            </Items>
          </telerik:RadDropDownList>
        </LayoutTemplate>
        <ItemTemplate>
          <telerik:RadDropDownListItem runat='server' data-sf-provider='<%# Eval("Provider.Name")%>'  data-sf-id='<%# Eval("Id")%>' data-sf-type="Telerik.Sitefinity.News.Model.NewsItem" >
          </telerik:RadDropDownListItem>
        </ItemTemplate>
    </telerik:RadListView>

  •  don't know if i am doing this correctly, but I have made a little progress with the below.
    I know that I should not be putting the Details Hyperlink object in the option like that, but that is how I get the text to show for the option (it does not rending anything but text).  Now I need to be able to get the URL the object would normally render.  Any help you can give would be greatly appreciated!

    <telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <LayoutTemplate>
            <select class="sfnewsList sfnewsListTitleDateSummary sflist" onchange="location = this.value;">
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            </select>
        </LayoutTemplate>
        <ItemTemplate>
          <option runat="server" class="sfnewsListItem sflistitem" TextDataField="Title" data-sf-field="Title" data-sf-ftype="ShortText" data-sf-provider='<%# Eval("Provider.Name")%>'  data-sf-id='<%# Eval("Id")%>' data-sf-type="Telerik.Sitefinity.News.Model.NewsItem" >
            <sf:DetailsViewHyperLink ID="DetailsViewHyperLink1" TextDataField="Title" ToolTipDataField="Description" data-sf-field="Title" data-sf-ftype="ShortText" runat="server" />
          </option>
        </ItemTemplate>
    </telerik:RadListView>
    <sf:Pager id="pager" runat="server"></sf:Pager>

  • You can receive url of news like that: <%# Eval("UrlName")%>">
    You can receive news title: <%# Eval("Title")%>

    For example, if you want to render option tag with news url inside value attribute, you need to use it like that

    <ItemTemplate>
            <option value="<%# Eval("UrlName")%>">
              <%# Eval("Title")%>
            </option>
        </ItemTemplate>

  • Hi Victor,

    Thank you so much for the help!  It got me a lot closer.  So the remaining issue is the URL.  The UrlName gives just the last part.  I am a little closer with the below.  However, I need to get the parent UrlName.  I have seen references to Parent.UrlName, but the template chokes when I stick that in an eval.  Is there an easy way to get it?

    <telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <LayoutTemplate>
            <select class="sfnewsList sfnewsListTitleDateSummary sflist" onchange="location = this.value;">
              <option label="Select a topic..." />
              <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            </select>
        </LayoutTemplate>
        <ItemTemplate>
          <option runat="server" value='<%# Eval("PublicationDate", "0:yyyy/MM/dd") + "/" + Eval("Urlname") %>' label='<%# Eval("Title")%>' class="sfnewsListItem sflistitem" TextDataField="Title" data-sf-field="Title" data-sf-ftype="ShortText" data-sf-provider='<%# Eval("Provider.Name")%>'  data-sf-id='<%# Eval("Id")%>' data-sf-type="Telerik.Sitefinity.News.Model.NewsItem" />
        </ItemTemplate>
    </telerik:RadListView>

  • So I finally came up with a solution with a little help from Telerik.  I am posting it here in case it is of benefit to anyone else looking to do the same or similar.  The hard thing for me to find was ItemDefaultUrl.  Once I figured out how to get that, the rest came together.

     

    <%@ Control Language="C#" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Comments.Web.UI.Frontend" TagPrefix="comments" %>
    <%@ Import Namespace="Telerik.Sitefinity.Web.UI" %>
    <%@ Import Namespace="Telerik.Sitefinity.Modules.Comments" %>
     
    <div class='newsList'>
      <div class='newsListTop'> </div>
      <div class='newsListBody'>
        <div class='newsListTitle'><span class='placeHolder'/></div>
        <div class='newsListDesc'><span class='placeHolder'/></div>
        <telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
          <LayoutTemplate>
              <select class="sfnewsList sfnewsListTitleDateSummary sflist newsListDropDown" onchange="location = this.value;">
                <option label="Select a topic..." />
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
              </select>
          </LayoutTemplate>
          <ItemTemplate>
            <option runat="server" value='<%# Request.Url.AbsoluteUri + Eval("ItemDefaultUrl") %>' label='<%# Eval("Title")%>' class="sfnewsListItem sflistitem" TextDataField="Title" data-sf-field="Title" data-sf-ftype="ShortText" data-sf-provider='<%# Eval("Provider.Name")%>'  data-sf-id='<%# Eval("Id")%>' data-sf-type="Telerik.Sitefinity.News.Model.NewsItem" />
          </ItemTemplate>
        </telerik:RadListView>
        <sf:Pager id="pager" runat="server"></sf:Pager>
      </div>
    </div>
      

  • Hi Brian,

    Thank you for the shared solution with the community.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items