Controls\ProductList.ascx
I have added new columns to the data grid and am now adding new Template Fields to the code behind the page. My question is how do I reference a field I added to the ProductDefinition (so a custom field). All of the code snippets I tried don't seem to work.
1. Container.DataItem["xxyfield"]
2. (CatalogItem)Container.DataItem["xxyfield"]
3. ((CatalogItem)Container.DataItem)["xxyfield"]
I also tried creating a function and used
item["xxyfield"]
Please Advise.
[545 byte] By [
Xcel] at [2008-1-29]
Hi,
Try using:
<%# DataBinder.Eval(Container.DataItem, "DisplayName").ToString() %>
Regards,
Brad
You need to use the third option but cast it to a CatalogItemsDataSet.CatalogItem. The product list control uses the DataSet representation of the product and not the strongly-type version.
((CatalogItemsDataSet.CatalogItem)Container.DataItem)["xxyfield"]
This still does not appear to be working.
If have pasted my code sample in. The field that I am looking to retrieve is Category which I have added to the Product Definition.
Please Advise.
<
asp:TemplateField meta:resourceKey="CategoryFieldName">
<ItemStyle CssClass="ProductNameColumn" /><HeaderStyle CssClass="ProductNameColumn" /><ItemTemplate><asp:HyperLink ID="Category" runat="server" EnableViewState="false" Text='<%# ((CatalogItemsDataSet.CatalogItem)Container.DataItem)["Category"] %>'NavigateUrl='<%# this.GetItemUrlString(Container.DataItem) %>'></asp:HyperLink></ItemTemplate></asp:TemplateField>Are you getting an error message or is it just not returning data?
The site returns an error.
If I go to the EventView of the Server it states: "Cannot Implicitly Convert type Object to type String. An explicit converstion exists (Are you missing a Cast?)"
Chris...
Ahh...My mistake:
((CatalogItemsDataSet.CatalogItem)Container.DataItem)["Category"].Value
I have tried that and unfortunately I am still getting the same error as above.
Joe,
I am still having an issue with this. Are you still investigating?
My main goal is to show a product thumbnail on this page.
Please Advise.
Yup, investigating this was item number 3 on my list of things to do today. Sorry it took so long to get back to you.
I have it working with the following:
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="TempLabel" runat="server" EnableViewState="false" Text='<%# ((CatalogItemsDataSet.CatalogItem)Container.DataItem)["ProductID"].ToString() %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>Also, make sure you set the "propertiesToReturn" attribute in web.config otherwise your column won't be returned in the browse and search results.
<
commerceSite ... propertiesToReturn="CategoryName,ProductID,CatalogName,i_ClassType,DisplayName,cy_list_price,myField">
...
</commerceSite>I hope this solves your problem.
Cheers,
Joe
Joe,
Unfortunately still a no go my end.
The Event Viewer states 'CatalogItemsDataSet' could not be found (are you missing a using directive or an assembly reference?) which I have posted below:
Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1310
Date: 11/21/2006
Time: 8:31:21 AM
User: N/A
Computer: SHUTTLE
Description:
Event code: 3007
Event message: A compilation error has occurred.
Event time: 11/21/2006 8:31:21 AM
Event time (UTC): 11/21/2006 1:31:21 PM
Event ID: 02d7298a072845629a80b25ccf09a301
Event sequence: 35
Event occurrence: 4
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/Root/DEPOTB2B-1-128085891110794474
Trust level: Full
Application Virtual Path: /DEPOTB2B
Application Path: C:\Inetpub\wwwroot\DEPOTB2B\
Machine name: SHUTTLE
Process information:
Process ID: 5732
Process name: w3wp.exe
Account name: XCELSOFTWARE\CSRunTimeUser
Exception information:
Exception type: HttpCompileException
Exception message: c:\Inetpub\wwwroot\DEPOTB2B\Controls\ProductList.ascx(35): error CS0246: The type or namespace name 'CatalogItemsDataSet' could not be found (are you missing a using directive or an assembly reference?)
Request information:
Request URL: http://192.168.1.72/DEPOTB2B/Browse.aspx
Request path: /DEPOTB2B/Browse.aspx
User host address: 192.168.1.122
User: removed
Is authenticated: False
Authentication Type: Site
Thread account name: XCELSOFTWARE\CSRunTimeUser
Thread information:
Thread ID: 14
Thread account name: XCELSOFTWARE\CSRunTimeUser
Is impersonating: False
Stack trace: at System.Web.Compilation.BuildManager.PostProcessFoundBuildResult(BuildResult result, Boolean keyFromVPP, VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetBuildResultFromCacheInternal(String cacheKey, Boolean keyFromVPP, VirtualPath virtualPath, Int64 hashCode)
at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath virtualPath, Boolean allowNoCompile)
at System.Web.UI.BaseTemplateParser.GetUserControlType(VirtualPath virtualPath)
at System.Web.UI.MainTagNameToTypeMapper.ProcessUserControlRegistration(UserControlRegisterEntry ucRegisterEntry)
at System.Web.UI.BaseTemplateParser.ProcessDirective(String directiveName, IDictionary directive)
at System.Web.UI.TemplateControlParser.ProcessDirective(String directiveName, IDictionary directive)
at System.Web.UI.PageParser.ProcessDirective(String directiveName, IDictionary directive)
at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)
Custom event details:
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Xcel,
CatalogItemsDataSet lives in Microsoft.CommerceServer.Catalog. If you're missing this reference in your code, then this won't compile. Make sure you add the reference to this library to your solution (I'm assuming you know how to do that).
If that doesn't fix it, change that casting from CatalogItemsDataSet to Microsoft.CommerceServer.Catalog.CatalogItemsDataSet.
Thank You Joe - this solved my problem.