The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
<%@ 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="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"categoriesCombo"
Skin
=
"Sitefinity"
/>
<
asp:Button
runat
=
"server"
ID
=
"filterBtn"
Text
=
"Filter"
/>
<
telerik:RadListView
ID
=
"NewsList"
ItemPlaceholderID
=
"ItemsContainer"
runat
=
"server"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
>
<
LayoutTemplate
>
<
sf:ContentBrowseAndEditToolbar
ID
=
"MainBrowseAndEditToolbar"
runat
=
"server"
Mode
=
"Add"
></
sf:ContentBrowseAndEditToolbar
>
<
ul
class
=
"sfnewsList sfnewsListTitleDateSummary"
>
<
asp:PlaceHolder
ID
=
"ItemsContainer"
runat
=
"server"
/>
</
ul
>
</
LayoutTemplate
>
<
ItemTemplate
>
<
li
class
=
"sfnewsListItem"
>
<
h2
class
=
"sfnewsTitle"
>
<
sf:DetailsViewHyperLink
ID
=
"DetailsViewHyperLink1"
TextDataField
=
"Title"
ToolTipDataField
=
"Description"
runat
=
"server"
/>
</
h2
>
<
div
class
=
"sfnewsMetaInfo"
>
<
sf:FieldListView
ID
=
"PublicationDate"
runat
=
"server"
Format
=
"{PublicationDate.ToLocal():MMM dd, yyyy}"
/>
</
div
>
<
sf:FieldListView
ID
=
"summary"
runat
=
"server"
Text
=
"{0}"
Properties
=
"Summary"
WrapperTagName
=
"div"
WrapperTagCssClass
=
"sfnewsSummary"
/>
<
sf:DetailsViewHyperLink
ID
=
"FullStory"
Text="<%$ Resources:NewsResources, FullStory %>" runat="server" CssClass="sfnewsFullStory" />
<
sf:ContentBrowseAndEditToolbar
ID
=
"BrowseAndEditToolbar"
runat
=
"server"
Mode
=
"Edit,Delete,Unpublish"
></
sf:ContentBrowseAndEditToolbar
>
</
li
>
</
ItemTemplate
>
</
telerik:RadListView
>
<
sf:Pager
ID
=
"pager"
runat
=
"server"
></
sf:Pager
>
<
asp:PlaceHolder
ID
=
"socialOptionsContainer"
runat
=
"server"
/>
public
override
string
LayoutTemplatePath
{
get
{
return
this
.layoutTemplatePath;
}
set
{
base
.LayoutTemplatePath = value;
}
}
private
string
layoutTemplatePath =
"~/CustomWidgets/News/Views/NewsMasterListViewCustomTemplate.ascx"
;
public
virtual
RadComboBox CategoriesCombo
{
get
{
return
this
.Container.GetControl<RadComboBox>(
"categoriesCombo"
,
false
);
}
}
public
virtual
Button FilterButton
{
get
{
return
this
.Container.GetControl<Button>(
"filterBtn"
,
false
);
}
}
protected
override
void
InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container, Telerik.Sitefinity.Web.UI.ContentUI.Contracts.IContentViewDefinition definition)
{
var dataItemType =
"Telerik.Sitefinity.News.Model.NewsItem"
;
//Get all taxa that have been used for the particular dataItemType
TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
var newsCategories = taxonomyManager.GetStatistics()
.Where(tS => tS.DataItemType == dataItemType && tS.TaxonomyId == TaxonomyManager.CategoriesTaxonomyId)
.Where(tS => tS.StatisticType == ContentLifecycleStatus.Live && tS.MarkedItemsCount > 0)
.Distinct()
.Select(t =>
new
{
taxonId = t.TaxonId,
taxonTitle = taxonomyManager.GetTaxon<HierarchicalTaxon>(t.TaxonId).GetString(
"Title"
),
}).ToList();
//bind the RadComboBox to the taxa
this
.CategoriesCombo.DataTextField =
"taxonTitle"
;
this
.CategoriesCombo.DataValueField =
"taxonId"
;
this
.CategoriesCombo.DataSource = newsCategories;
this
.CategoriesCombo.DataBind();
//Add a default EmptyItem
RadComboBoxItem emptyItem =
new
RadComboBoxItem(
"Choose category"
);
this
.CategoriesCombo.Items.Insert(0, emptyItem);
protected
override
IQueryable<Telerik.Sitefinity.News.Model.NewsItem> GetItemsList(
ref
int
? totalCount)
{
//check if a category to filter by is selected and add it to the filter expression
if
(
this
.CategoriesCombo.SelectedIndex > 0)
{
this
.FilterExpression +=
string
.Format(
" AND Category.Contains(({0}))"
,
this
.CategoriesCombo.SelectedValue.ToString());
}
//populate items list
return
base
.GetItemsList(
ref
totalCount);
}
protected
override
void
OnPreRender(EventArgs e)
{
int
? totalCount = 0;
IQueryable<NewsItem> query =
this
.GetItemsList(
ref
totalCount);
this
.InitializeListView(query, totalCount);
base
.OnPreRender(e);
}
Boyan Barnev is a Principal Information Developer at Progress. His mission is to demonstrate the unlimited capabilities of Sitefinity CMS via product documentation, SDK samples, and technical blog posts. He has graduated from the American University in Bulgaria and joined Telerik in 2011. Since then Boyan has held various positions in the company, leading the strategy and operation of the Sitefinity CMS Technical support service worldwide.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.