How to ensure selected item transformation in query repeater

   —   
This article shows example how to ensure selected item transformation in query repeater. We will work with cms.news document type in this example.
You will need to create copy of query repeater web part first. Then you will need to change following code in its code-behind:
    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();
    }


to:

    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();
        int newsID = CMS.GlobalHelper.QueryHelper.GetInteger("newsid", 0);
        if (newsID > 0)
        {
            repItems.WhereCondition = "NewsID = " + newsID.ToString();
            repItems.TransformationName = "cms.news.default";
        }
    }


In addition you will need to use following sample code in transformation to generate link to particular 'news' item in the list:

<a href="<%# GetDocumentUrl() %>?newsid=<%# Eval("NewsID") %>"><%# Eval("NewsTitle") %></a>

See also:

Applies to: Kentico CMS 4.0. May work in previous versions as well.
Share this article on   LinkedIn Google+