Nil Pun
Nil Pun

Reputation: 17373

Sitecore items relationship

I'm quiet new to sitecore. I'm building a holiday plan page where each plan has different packages and each package have attributes associated with package. The table shows list of packages and it's attribute. When clicked on package column, detailed html table show with package detail and picture on same page.

I notice sitecore stores every ID as GUID. I do not want to pass this to client side. Is there any way we can have numeric ID for each item in sitecore such that I can relate each Package with package detail and do jquery client side show hide for each click etc?

Thanks.

Upvotes: 1

Views: 268

Answers (1)

Martin Davies
Martin Davies

Reputation: 4456

If we can make the assumption the the packages are child items of the holiday plan, then you Then you might set the data source of your list of packages to:

Sitecore.Context.Item.Children

To then create links to the details of each package item, you might do something like this:

// ... in the itemdatabound event of the listview / repeater etc etc ...

var link = (Hyperlink)e.Item.FindControl("MyHyperlinkControl");
var currentItem = (Item)e.Item.DataItem;

link.NavigateUrl = LinkManager.GetItemUrl(currentItem);

// ... all the other binding related activity ...

I think a typical way to load this content in via Jquery is to use the load() method using the url of the hyperlink, and specify an anchor on the target page:

$('#result').load('holidays/package1 #PackageDetailsContainer');

http://api.jquery.com/load/

However, if you really want to select items by a key, you can filter Sitecore items by any of their properties or fields using linq. For example:

var selectedPackageKey = Request.QueryString["packageKey"];

var parentFolderId = "{xxxx.xxxxxxx.xxxxxxxx.xxxxxxxxx}";
var parentFolderItem = Sitecore.Context.Database.GetItem(parentFolderId);

var selectItem = parentFolderItem.Children.
                                  Where(i => i["Key field"] == selectedPackageKey).
                                  FirstOrDefault();

Upvotes: 1

Related Questions