How to use query repeater as nested repeater

   —   
This article describes how to use query repeater as nested repeater. Regrettably, query repeater is not nativelly supported for being used as nested repeater as it doesn't have 'DelayedLoading' property.
Let's say we have 2 custom tables: 'Module' and 'Team' and we want to display list of 'Teams' in outer repeater and for each team we want to display list of modules this team manages. The ID of record from 'Team' table (primary key) is stored as 'itemId' column in 'Team' table and the foreign key from Module to Team is stored in 'Team' column in 'Module' table. You can use following sample code in transformation of outer repeater (the part where you set where condition is displayed in bold text):

<cms:queryrepeater StopProcessing="false" runat="server" ID="qrModules" QueryName="CMS.Module.selectall" TransformationName="CMS.Module.List" OrderBy="ModuleName ASC" />

<script runat="server">

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (this.Parent is IDataItemContainer)
        {
          IDataItemContainer cont = this.Parent as IDataItemContainer;
          if (cont != null)
          {
            System.Data.DataRowView drv = (System.Data.DataRowView)cont.DataItem as System.Data.DataRowView;
            if (drv != null)
            {

              string teamId = ValidationHelper.GetString(drv["itemId"], "");
              if (teamId != "")
              {
                qrModules.WhereCondition= "Team = " + teamId;
                qrModules.ReloadData(true);
              }


            }
            else
            {
              Response.Write("Error: DataRowView is null");
            }
          }
          else
          {
            Response.Write("Error: IDataItemContainer is null");
          }
        }
    }

</script>


Basically you can use any column name from your custom table or document type table as index for 'drv' datarow.

-md-


See also:

Applies to: Kentico CMS 4.x, 5.x
Share this article on   LinkedIn