November Happy Hour will be moved to Thursday December 5th.

mixing newslists

Vote:
 
Hi, I´m trying to mix 3 different newslist in to one and sort them by date. This is my code: <%#((datetime)container.currentpage["pagestartpublish"]).tostring("yyyy-mm-dd")%> | KÄLLA
<%#striphtml(container.currentpage.property["pagename"].tostring(),maxcharactersincorpnews())%>

I also have this code in the code behind: NewCorpNewsList.DataBind(); NewMetalStrcturesNewsList.DataBind(); NewFastenersNewsList.DataBind(); NewCorpMetalStructuresFastenerNewsList.DataBind(); It just doesn't work. Nothing gets printed. Can anybody help me with this?
#12644
May 23, 2006 10:39
Vote:
 
Hello Stefan. Reviewing your code sample, the following comes to mind as possible reasons for your problem. First, the top 3 newslist controls will simply have no content. There are two primary ways to assign contents to a list: either you assign a "starting point" by using the PageLink or PageLinkProperty attributes, or you assign content by setting DataSource. (You can also combine the two, which is what you have attempted to do.) The very first list ("NewCorpNewsList") uses neither of these mechanisms, as will thus be empty. The second and third list are also missing PageLink or PageLinkProperty, and will simply contain the contents of the first list (which is empty). You have to indicate the location of your desired pages to these lists. Your fourth list ("NewCorpMetalStructuresFastenerNewsList"), however, correctly uses PageLink to retrieve some content (plus the empty content retrieved by the use of DataSource). You supply the list with a PageReference to the current page, meaning it should show all child pages to the current page - IF they are of the correct page type (PageTypeID=6). So you should be able to see some content in this final list, if you have any pages below the page you are viewing, that fulfil the conditions. Also make sure you are not accidentally using a negative or zero MaxCount (from the GetCount() method). Also, since the first 3 lists do not perform any rendering, you could probably use the PageListData control instead of NewsLists - it is a more basic control with no rendering support, and as such should be slightly more "light weight" (from a performance standpoint). If your goal is to display all pages of a certain page type, regardless of where they are placed in the Web site structure, linked lists might not be the ultimate solution for you. Perhaps a property based search would fulfil your needs better.
#14669
May 23, 2006 14:05
Vote:
 
Thanks for all the help! But i solved it in an other way in the code-behind and it works fine: PageDataCollection News = new PageDataCollection(); PageReference pageLinkCorp = new PageReference(Int32.Parse(CurrentPage["NewsContainer"].ToString())); PageReference pageLinkMetalStructures = new PageReference(Int32.Parse(CurrentPage["MetalStructuresNewsContainer"].ToString())); PageReference pageLinkFasteners = new PageReference(Int32.Parse(CurrentPage["FastenersNewsContainer"].ToString())); //Corp PageDataCollection NewsGroups = GetChildren( (PageReference) pageLinkCorp); for(int i=0; i < NewsGroups.Count; i++) News.Add(NewsGroups[i]); //Metal Structures NewsGroups = GetChildren( (PageReference) pageLinkMetalStructures); for(int i=0; i < NewsGroups.Count; i++) News.Add(NewsGroups[i]); //Fasteners NewsGroups = GetChildren( (PageReference) pageLinkFasteners); for(int i=0; i < NewsGroups.Count; i++) News.Add(NewsGroups[i]); News.Sort(new SortPagesComparer()); FinnvedenGroupNews.DataSource = News; FinnvedenGroupNews.DataBind();
#14670
May 24, 2006 10:22
Vote:
 
Great, as you have noted, things can often be solved in multiple ways. I would like to add a few comments on your more recent code, just to simplify things for you (and also try to solve your initial attempt using tags): First, the multiple typecasts and parses you use for your PageReference properties are not required. With your current syntax, you retrieve the property value as an object (using CurrentPage["NewsContain"] syntax), convert it to a string, parse that string to an integer, and then you create a new PageReference instance based on that integer. You also have a final (not needed) typecast to PageReference in your GetChildren calls. That is a bit of overkill - try using the following, to retrieve your property values as PageReferences: (PageReference)CurrentPage["NewsContainer"] Second, you are using three for-loops to add all the results from your GetChildren calls into the PageDataCollection "News". These loops are not necessary, as you can use the PageDataCollection.Add(...) method to add entire collections at once. So I believe your code could be compacted into something like this (untested): PageDataCollection News = new PageDataCollection(); News.Add(GetChildren((PageReference) CurrentPage["NewsContainer"])); News.Add(GetChildren((PageReference) CurrentPage["MetalStructuresNewsContainer"])); News.Add(GetChildren((PageReference) CurrentPage["FastenersNewsContainer"])); News.Sort(...) etc etc Note: If you'd like to make sure your properties contain values before trying to typecast or access them (to prevent from null reference exceptions and similar), PageBase offers an IsValue("PropertyName") method that should be checked before accessing/using property values to add robustness. To return to your first attempt at solving this, something like the following (again, untested) should be able to handle it from the aspx file: etc etc Just make sure the controls are data bound (call from code-behind), and the above should work. If you'd like to add custom sorting etc, you can still do that from the code-behind (or use the SortOrder or SortBy/SortDirection attributes of the NewsList tag).
#14671
May 29, 2006 15:09
* 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.