SyracuseCheer

I'm currently trying to create a grid of Categories and Sub Categories on the homepage of our eStore. I'm actually using a DataList, but the output is tabular so I'm using the term "grid". I'm not using a GridView control.

I've been able to retrieve the name of each category and put them into a label in the ItemTemplate of the DataList. That's working great. The problem is that I really want a Hyperlink control rather than a Label control, and I can't figure out how to generate the URL.

I've been trying to follow the code in the CatalogSiteMapProvider and the CatalogItemUri class, but I can't figure out how the StarterSite is generating those URLs.

As always, your assistance is greatly appreciated!



Re: Commerce Server 2007 Creating URLs for Categories

SyracuseCheer

Nevermind...this one was easy...

Assuming you have a category object, simply use the following:

Code Snippet


Category thisCat;
thisCat = (Category)e.Item.DataItem; // I'm getting this from a
// DataList control

HyperLink lnkThisCatLink = (HyperLink)e.Item.FindControl("lnkCategory");

lnkThisCatLink.Text = thisCat.DisplayName;
CategoryUri thisItemURI = new CategoryUri(thisCat);
lnkThisCatLink.NavigateUrl = thisItemURI.GetUrl(false).ToString();



I hope this is helpful for anyone out there.