Technical support This forum is closed.
Version 1.x > Technical support > problems with sorting dataset populating nested repeater View modes: 
User avatar
Member
Member
calcat - 11/29/2006 11:04:49 PM
   
problems with sorting dataset populating nested repeater
Hi,

I have a nested repeater with the outer repeater being days of the month and defined as cms.MenuItem. The inner repeater contains the events for that day and the events are defined as cms.calendarevent.

I have defined a parent-child relation between the two and can print out the information just fine. The problem being that I want to insure that November 3, 2006 and its events is rendered before say November 21, 2006 and its events so I would like the outer repeater to be sorted by "MenuItemOrder" a number that the user can control when creating the documents.

Here is the code in my .cs file

//create the datarelation:
System.Data.DataRelation myrelation;
System.Data.DataColumn MasterCol1;
System.Data.DataColumn Detailcol1;

String[] classNames = "cms.menuitem;cms.calendarevent".Split(';');

//create a new TreeProvider instance
TreeProvider tree = WebProject.Functions.GetTreeProvider();

//read all documents of type "cms.menuitem" and "cms.calendarevent"
DataSet ds = tree.SelectNodes("/News---Events/Calendar/" + pathArray[3] + "/%",
TreePathTypeEnum.AliasPath, classNames, "");

MasterCol1 = ds.Tables["cms.menuitem"].Columns["MenuItemID"];
Detailcol1 = ds.Tables["cms.calendarevent"].Columns["DayID"];

//add parent-child relation among tables
myrelation = new System.Data.DataRelation("Myrelation", MasterCol1, Detailcol1);
ds.Relations.Add(myrelation);
//set data source for the parent repeater
parentMonth.DataSource = ds.Tables["cms.menuitem"];
//parentMonth.SelectNodesOrderBy = "[cms.menuitem].[MenuItemOrder]";

//bind data
parentMonth.DataBind();

Using this I get the following display
November 28, 2006
event 1
event 2
November 3, 2006
event 1
etc.

If I add the sortby parameter

//read all documents of type "cms.menuitem" and "cms.calendarevent"
DataSet ds = tree.SelectNodes("/News---Events/Calendar/" + pathArray[3] + "/%",
TreePathTypeEnum.AliasPath, classNames, "", "MenuItemOrder");

I get the following error:
Exception Details: System.Exception: Kentico.CMS.DataProviderSQL.ExecuteQuery: Query: SELECT view_cms_tree_joined.*, [CMS_calendarevent].* FROM view_cms_tree_joined INNER JOIN [CMS_calendarevent] ON view_cms_tree_joined.foreignkeyvalue = [CMS_calendarevent].[calendareventID] WHERE ( (AliasPath LIKE N'/News---Events/Calendar/November/%') ) AND classname = 'CMS.calendarevent' ORDER BY MenuItemOrder : caused exception: Invalid column name 'MenuItemOrder'.

If you will notice, it says that the classname is "CMS.calendarevent" which does not contain the column "MenuItemOrder" which is true, but I want to sort the class "menuItem" not "calendarevent".

If I change the sortby parameter to a column name of the calendarevent class:
//read all documents of type "cms.menuitem" and "cms.calendarevent"
DataSet ds = tree.SelectNodes("/News---Events/Calendar/" + pathArray[3] + "/%",
TreePathTypeEnum.AliasPath, classNames, "", "eventTitle");

I get the following error:
Exception Details: System.Exception: Kentico.CMS.DataProviderSQL.ExecuteQuery: Query: SELECT view_cms_tree_joined.*, [CONTENT_MenuItem].* FROM view_cms_tree_joined INNER JOIN [CONTENT_MenuItem] ON view_cms_tree_joined.foreignkeyvalue = [CONTENT_MenuItem].[MenuItemID] WHERE ( (AliasPath LIKE N'/News---Events/Calendar/November/%') ) AND classname = 'CMS.MenuItem' ORDER BY eventTitle : caused exception: Invalid column name 'eventTitle'.

Now it says that the classname is "CMS.MenuItem" (which I wanted in the first place, but not with the sortby from an item of class "calendarevent".

I have tried everything I can think of and find in terms of adding table name, class name, etc., but I can't seem to get it right.

Any and all help is much appreciated!!

Thank you!

User avatar
Member
Member
calcat - 12/6/2006 8:57:28 PM
   
Re: problems with sorting dataset populating nested repeater
Hi all,

OK, I'm a little slow - I didn't realize I was looking at the solution and just didn't recognize it at first.

I see now that the SelectNode was applying the ORDER BY to both classes which was a problem since they don't contain the same column names. So, I went ahead and did like was suggested in another post - created 2 datasets, one for the menuitems and one for the calendarevents, sort each individually, merge them and then apply the relation to the merged set. It works great.