Accessing Page Description from ascx
Hi,
I'm trying to migrate the Simplicity template to 5.x, and I have a problem with their custom navigation control. See the code below:
<%@ Control Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="sfMap" %>
<
telerik:RadTabStrip
ID
=
"RadPanelbarNav"
runat
=
"server"
Visible
=
"false"
/>
<
asp:Repeater
ID
=
"Repeater1"
runat
=
"server"
DataSourceID
=
"SiteMapDataSource"
>
<
HeaderTemplate
>
<
ul
class
=
"nav-holder"
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
li
>
<
a
href='<%# Eval("Url") %>' runat='server'>
<
h3
><%#Eval ("Title") %></
h3
>
<
p
><%#Eval("Description")%></
p
>
</
a
>
</
li
>
</
ItemTemplate
>
<
FooterTemplate
>
</
ul
>
</
FooterTemplate
>
</
asp:Repeater
>
<
sfMap:SitefinitySiteMapDataSource
runat
=
"server"
ID
=
"SiteMapDataSource"
StartingNodeOffset
=
"0"
ShowStartingNode
=
"false"
/>
Hello,
That's a tough one, unfortunately there is no way to access the Description field on a PageSiteNode if you don't get the PageNode itself - SitefinitySiteMapDataSource is a special control we've developed to provide the best performance when working with custom navigation controls, as it gives you the cached output from the pages provider, and also takes care of things like ShowInNavigation, group pages behavior etc.
However you can easily subscribe to the repeater ItemDataBound event and do something like:
protected
void
Page_Load(
object
sender, EventArgs e)
Repeater1.ItemDataBound +=
new
RepeaterItemEventHandler(Repeater1_ItemDataBound);
void
Repeater1_ItemDataBound(
object
sender, RepeaterItemEventArgs e)
if
(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
var item = e.Item.DataItem
as
PageSiteNode;
var pageManager = PageManager.GetManager();
PageNode pageNode;
using
(
new
ElevatedModeRegion(pageManager))
pageNode = pageManager.GetPageNode(item.Id);
Label descrLabel = e.Item.FindControl(
"descrLbl"
)
as
Label;
if
(descrLabel !=
null
&& pageNode.Page !=
null
)
descrLabel.Text = pageNode.Page.Description.ToString();
Basically what I need is the description (or something else) in addition to just the page title. I found this thread and it seemed like it would work, unfortunately I'm brand new to Sitefinity, C#sharp, and I'm pretty much a front front end guy to boot. So how would I use the code you've suggested above (meaning where would I put it). Do I need a codefile in addition to the MainNavigation.ascx that Simplicity uses? or where would I put that code? Do you have another suggestion?
Thanks for your help!
Hello Richard,
Yes, the sample is actually the codefile added to the ascx template for MainNavigation.ascx.
Please note you will need to add a label with ID descrLbl
on the frontend, which will be the container for the Description text.
Greetings,
Boyan Barnev
the Telerik team
Hey Boyan, Thanks for the input. I put the sample code in a codefile and I'm getting an error
Compiler Error Message: CS1518: Expected class, delegate, enum, interface, or struct