Try our conversational search powered by Generative AI!

Filter PagesTypes from a PageTree

Vote:
 

Hello!

Iam having a PageTree and everything is working fine. But I want to filter out pages of a certain page type. How do I do that best?

Iam trying to follow Fredrik Vigs guide:
http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/

Looking at the header "Filtering the data", Iam trying to achive that but, as I said, with Page Types. Any ideas?

private void MyPageList_Filter(object sender, FilterEventArgs e)
{
    var pages = e.Pages;
 
    for (int i = pages.Count - 1; i > -1; i--)
    {
	if (!pages[i].PageName.ToUpper().StartsWith("A"))
	{
	    pages.RemoveAt(i);
	}
    }
}
#59508
Jun 13, 2012 14:46
Vote:
 
Cant you just check the PageType property instead of PageName?

private void MyPageList_Filter(object sender, FilterEventArgs e)
{
    var pages = e.Pages;
 
    for (int i = pages.Count - 1; i > -1; i--)
    {
	if (pages[i].PageTypeName == "YourPageTypeNameHere")
	{
	    pages.RemoveAt(i);
	}
    }
}
#59509
Jun 13, 2012 15:13
Vote:
 

Yes, I see. Ok Yeah. Thank you =)

#59510
Jun 13, 2012 15:39
Vote:
 

It did work but ... Just out of couriosity:

for (int i = pages.Count - 1; i > -1; i--)
May I just ask, why it is '-1'?

Why not
for (int i = pages.Count; i > 0; i--)

#59707
Jun 22, 2012 18:27
Vote:
 

a list with 1 items have Count = 1 but pages[0] is that page. pages[1] will throw an error

#59708
Jun 22, 2012 18:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.