Hello there----
I have added VIEW ALL Linkbutton on Manufacturer/productingrid.ascx control........to view all the products made by the same manufacturer......
The designer file is---------------
<asp:LinkButton ID="LinkButton1" runat="server" Text="View All" CssClass="Viewallhyperlink"
OnCommand="dl_viewall" CommandArgument="dlnew" CommandName="Viewall"></asp:LinkButton>
while the code is---------------
protected void dl_viewall(object sender, CommandEventArgs e)
{
LinkButton lb = (LinkButton)sender;
// DataList dl = (DataList)lb.Parent.Parent.Parent.Parent;
if (lb.CommandName == "Viewall")
{
dlProducts.DataSource = ManufacturerManager.GetProductsByManufacturer(ManufacturerId);
dlProducts.DataBind();
productsPager.Visible = false;
}
}
I have made the method to get all products which is----------
public static List<ProductManufacturer> GetProductsByManufacturer(int manufacturerId)
{
var context = ObjectContextHelper.CurrentObjectContext;
var query = from mid in context.ProductManufacturers
from pid in context.Products
where pid.ProductId == mid.ProductId && mid.ManufacturerId == manufacturerId && pid.Deleted == false && pid.Published == true
select mid;
var queryresult = query.ToList();
return queryresult;
}
When i debug this project it shows me the number of products by the manufacturer but when it reaches to Productbox1.ascx control to bind data in this page's datalist it gives me an error which is-----------
Unable to cast object of type 'System.Data.Entity.DynamicProxies.ProductManufacturer_1FB1FE3FB05820267E1F4A4ACFD563A3233BDF00631C7C5E4F4848DB890FE1A4' to type 'NopSolutions.NopCommerce.BusinessLogic.Products.Product'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Data.Entity.DynamicProxies.ProductManufacturer_1FB1FE3FB05820267E1F4A4ACFD563A3233BDF00631C7C5E4F4848DB890FE1A4' to type 'NopSolutions.NopCommerce.BusinessLogic.Products.Product'.
Source Error:
Line 67: RepeatLayout="Table" ItemStyle-CssClass="item-box">
Line 68: <ItemTemplate>
Line 69: <nopCommerce:ProductBox1 ID="ctrlProductBox" Product='<%# Container.DataItem %>'
Line 70: runat="server" />
Line 71: </ItemTemplate>
Source File: e:\new projects\nopcommerce 1.8\NopCommerceStore\Templates\Manufacturers\ProductsInGrid.ascx Line: 69
I can't find the solution to this error..........Please help me by solving this problem.
Do needful on ergent basis