Configure Querry Repeater from code behind

Mateusz Żebrowski asked on December 2, 2014 15:51

I've got this code

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="My.ascx.cs" Inherits="CMSGlobalFiles_MY" %>
<cms:QueryRepeater ID="QueryRepeater" runat="server" ZeroRowsText="none"></cms:QueryRepeater>

and in code behind:

 protected override void OnInit(EventArgs e)
{

    base.OnInit(e);
    QueryRepeater.QueryName = "my.samplatable.selectall";
    QueryRepeater.TransformationName = my.samplatable.Default";
}

And I get "none" (it's ZeroRowText). When i write: <cms:QueryRepeater ID="QueryRepeater" runat="server" ZeroRowsText="none" TransformationName="my.samplatable.Default" QueryName="my.samplatable.selectall"></cms:QueryRepeater> it works perfect. What am I missing?

Recent Answers


Ivan Robalino answered on December 2, 2014 17:20

Hi Mateus

Add the following lines after you set queryrepeater transformation and you should get expected content

QueryRepeater.DataBindByDefault = false; QueryRepeater.StopProcessing = false; QueryRepeater.ReloadData(true);

0 votesVote for this answer Mark as a Correct answer

Mateusz Żebrowski answered on December 2, 2014 18:19

No. It's not working. Besides it shold be QueryRepeater.ReloadData=true

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 2, 2014 21:16

Ivan was correct on the ReloadData(true) but this is for v8 not v7 which you are using.

Are you using this in a webpart? If so, your event you perform your work in should be public override void OnContentLoaded() This happens before the OnInit() event does.

If you're not using it in a web part then try loading the repeater data later like page load or prerender.

0 votesVote for this answer Mark as a Correct answer

Sandro Jankovic answered on December 3, 2014 11:40

Hi Mateusz,

Would it be possible to confirm which version you are using?

I was able to set the properties in the codebehind using the same code, the only change I made was adding ReloadData(true). I tested this in v7 with the latest hotfix as you seem to be using v7, please let me know if that is not the case.

   protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        QueryRepeater1.QueryName = "customtable.SampleTable.test";
        QueryRepeater1.TransformationName = "customtable.SampleTable.Default";
        QueryRepeater1.ReloadData(true);
    }
0 votesVote for this answer Mark as a Correct answer

Ivan Robalino answered on December 4, 2014 20:37

Hi Brenden

QueryRepeater.ReloadData(true) is also available in v7. I use it all the time in such version and if you check standard webpart code behind file "~/CMSWebParts/Viewers/Query/queryrepeater.ascx.cs" you will see its usage inside of method "ReloadData"

1 votesVote for this answer Mark as a Correct answer

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