Displaying different list formats depending on PageType

Vote:
 
Hello, I would like to change the display of a list depending on the page type. If my page type is News, then I display the list differently than if it was a list of ordinary pages or documents for example. The way I've done it is by creating different panels and making them visible depending on the selection of the user to a particular page type. This is not a very good solution as all the panels will be created but only one will actually be shown on the page. Is there a better way to do this, perhaps programmatically? CS Code private void Page_Load(object sender, EventArgs e) { if (IsValue("ListingType")) { _pageType = (string) CurrentPage["ListingType"]; switch (_pageType) { case "3":/* Statements of the S-G */ DocumentListControl.PageTypeID = Convert.ToInt32(_pageType); PageListControl.Visible = false; NewsListControl.Visible = false; DocumentListControl.Visible = false; HighlightListControl.Visible = true; break; case "17": /* News */ NewsListControl.PageTypeID = Convert.ToInt32(_pageType); PageListControl.Visible = false; NewsListControl.Visible = true; DocumentListControl.Visible = false; HighlightListControl.Visible = false; EventsListControl.Visible = false; break; case "18":/* Highlight */ DocumentListControl.PageTypeID = Convert.ToInt32(_pageType); PageListControl.Visible = false; NewsListControl.Visible = false; DocumentListControl.Visible = false; HighlightListControl.Visible = true; EventsListControl.Visible = false; break; case "28":/* Events */ DocumentListControl.PageTypeID = Convert.ToInt32(_pageType); PageListControl.Visible = false; NewsListControl.Visible = false; DocumentListControl.Visible = false; HighlightListControl.Visible = true; EventsListControl.Visible = true; break; case "36":/* Document */ DocumentListControl.PageTypeID = Convert.ToInt32(_pageType); PageListControl.Visible = false; NewsListControl.Visible = false; DocumentListControl.Visible = true; HighlightListControl.Visible = false; EventsListControl.Visible = false; break; case "7": case "44":/* Press */ case "45":/* Board Actions */ default:/* Ordinary Pages */ PageListControl.PageTypeID = 7; PageListControl.Visible = true; NewsListControl.Visible = false; DocumentListControl.Visible = false; HighlightListControl.Visible = false; break; } } ASPX Code
<%-->--%>
" title="<%#container.previewtext%>" class="NewsLink"> <%#container.currentpage.pagename%>   (<%#((datetime)container.currentpage["pagestartpublish"]).tostring("yyyy-mm-dd hh:mm")%>)
<%#container.previewtext%>
<%-->--%>
" alt="" />
<%-->--%>




  • etc...
    #13080
    Mar 25, 2008 18:35
    Vote:
     
    This answer was given to me. You’re right about NEVER using Page ID’s for anything but a quick test. To check the PageType you can use the following: CurrentPage.PageType=”NormalPage” etc... ie you use the name of the PageType for the switch, however if the names change you get into trouble so I would “fool-proof” it so it doesn’t blow up J (if the name doesn’t exist or is null...) PageType etc is also part of the EPiServer.DataAbstraction namespace – this includes everything about the system tables PageTypes, Users etc...
    #15374
    Mar 25, 2008 18:47
    Vote:
     
    Hi, Victor. If you are using asp.net 2.0 You should look into the multiview control: Content of Viewmode 1 goes here Content of Viewmode 2 goes here Where SetActiveView goes something like this: protected void SetActiveView() { switch(conition) { case contion1: uxMultiView.SetActiveView(View1); break; case contion2: uxMultiView.SetActiveView(View2); break; } } Please let me know if this helps, or you need some more help.
    #15375
    Mar 25, 2008 18:47
    Vote:
     
    Thank you so much for the info. I scrambled a bit to find a solution the following solution. I broke up the code into various controls and used a switch in the main control to load the appropriate control depending on the page type list. Here's the code: using System; using System.Web.UI; using EPiServer; namespace Unctad.Web.Templates.Units { public partial class ListingWithPaging : UserControlBase { private void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string _pageType; _pageType = (string)CurrentPage["ListingType"]; switch (_pageType) { case "3":/* Statements of the S-G */ Control c1 = LoadControl("ListingSGStatements.ascx"); Controls.Add(c1); break; case "News": /* News */ Control c2 = LoadControl("ListingNews.ascx"); Controls.Add(c2); break; case "Highlight":/* Highlight */ Control c3 = LoadControl("ListingHighlights.ascx"); Controls.Add(c3); break; case "Event":/* Events */ Control c4 = LoadControl("ListingEvents.ascx"); Controls.Add(c4); break; case "Webflyer":/* Document */ Control c5 = LoadControl("ListingDocuments.ascx"); Controls.Add(c5); break; case "Ordinary web page": case "PressRelease":/* Press */ case "BoardAction":/* Board Actions */ default:/* Ordinary Pages */ Control c8 = LoadControl("ListingPages.ascx"); Controls.Add(c8); break; } if (!IsValue("ListingContainer")) { Controls.Clear(); return; } } } It seems to work although it might not be as elegant as the solution you provided. I will try to apply this solution instead. Thanks again. Victor
    #15376
    Mar 25, 2008 18:47
    Vote:
     
    I applied the MultiView to my pages but had to modify the code a little bit to make it work. The funny thing is that my Pagination doesn't work anymore. Any ideas why? ascx
    <%----%>
    <%#Container.CurrentPage.PageName%>   (<%#((DateTime)Container.CurrentPage["PageStartPublish"]).ToString("yyyy-MM-dd hh:mm")%>)
    <%#Container.PreviewText%>
    <%----%>
    ...[etc]
    ascx.cs using System; using EPiServer; using EPiServer.Core; using EPiServer.WebControls; namespace Unctad.Web.Templates.Units { public partial class ListingWithPaging : UserControlBase { private void Page_Load(object sender, EventArgs e) { PagingControl customPaging = new PagingControl(); customPaging.NextPagingItemText = "Next"; customPaging.PrevPagingItemText = "Previous"; PageListControl.PagingControl = customPaging; NewsListControl.PagingControl = customPaging; DocumentListControl.PagingControl = customPaging; PageListControl.DataBind(); NewsListControl.DataBind(); DocumentListControl.DataBind(); if (!IsPostBack) { string _pageType; _pageType = (string)CurrentPage["ListingType"]; switch (_pageType) { //case "3":/* Statements of the S-G */ // break; case "News": /* News */ ucMultiView.SetActiveView(viewNews); break; case "Highlight":/* Highlight */ ucMultiView.SetActiveView(viewDocuments); break; case "Event":/* Events */ ucMultiView.SetActiveView(viewEvents); break; //case "PressRelease":/* Press */ // break; //case "BoardAction":/* Board Actions */ // break; case "SGStatement":/* Statements of the S-G */ case "Ordinary web page": case "PressRelease":/* Press */ case "BoardAction":/* Board Actions */ default:/* Ordinary Pages */ ucMultiView.SetActiveView(viewPages); break; } } } protected int GetCount() { if (!IsValue("ListingCount")) return -1; return (int)CurrentPage["ListingCount"]; } protected static string GetNewsThumbnailImage(PageData pd) { return pd["ThumbnailNews"] != null ? Global.EPConfig.HostUrl + pd["ThumbnailNews"] : Global.EPConfig.HostUrl + "/upload/img/news/thumbnails/news_en.gif"; } protected static string GetThumbnailImage(PageData pd) { return pd["Image55x74"] != null ? Global.EPConfig.HostUrl + pd["Image55x74"] : Global.EPConfig.HostUrl + "/upload/img/pub/medium/unctad_doc.gif"; } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }
    #15377
    Mar 25, 2008 18:47
    Vote:
     
    Another approach would be to derive a new control from PageListData, and apply a Template "scheme" based on the PageType it "supports". (Compare with how the TemplateColumn works with the DataGrid control) It could possibly look something like this in the markup code: The upside would be that you quite easily can manage new pagetypes without having to make modifications to codebehind. Regards, Johan Olofsson EPiServer AB
    #15378
    Mar 25, 2008 18:47
    * You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.