Update repeater based on dropdown value

Jenilyn Sanchez asked on September 5, 2018 16:25

Hi,

Need some help in filtering. I'm using portal engine method and it's my first time developing website using kentico. I have a repeater for the list of news, then I have in header a drop down for the list of months. How can I possibly update the repeater content based on the month selected in the drop down. Thanks for the help.

Recent Answers


Peter Mogilnitski answered on September 5, 2018 16:53 (last edited on December 10, 2019 02:31)

Your drop down can reload your page with some parameter i.e. mysite.com?month=5 and then in your repeater in where condition you can put macro like: {% String.IsNullOrEmpty(QueryString["month"])? "" : " month = " + QueryString["month"] |(identity)GlobalAdministrator%}

1 votesVote for this answer Mark as a Correct answer

Dragoljub Ilic answered on September 5, 2018 16:58

Hi Jenilyn,

You should take a look into developing custom filter in documentation. Your filter should be implemented almost in the exact way is in documentation, only SQL query should be different, something like:

if (this.MonthDropDown.SelectedValue != null)
{
    // Gets the month as integer
    int month = ValidationHelper.GetInteger(this.MonthDropDown.SelectedValue, -1);

    if (month > -1)
    {
        where = $"(DATEPART(MONTH, [DocumentPublishFrom]) = {month})";
    }
}

After that, you should add filter on page template and bind it to your repeater.

Best regards, Dragoljub

1 votesVote for this answer Mark as a Correct answer

Jenilyn Sanchez answered on September 6, 2018 03:46

Thank you guys for the idea. Will try both

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.