开发者

Databinding: does not contain a property with the name 'CategoryId' error

开发者 https://www.devze.com 2023-03-15 07:13 出处:网络
I am going through a tutorial and trying out something when I got this error with this line, can someone advice, thanks:

I am going through a tutorial and trying out something when I got this error with this line, can someone advice, thanks:

<ItemTemplate>               

<a class='MostPopularItemText' href='ProductDetails.aspx?productID=<%# Eval("ProductId") %>&&CategoryId=<%# Eval("CategoryId") %>'><%# Eval("ModelName") %></a><br />                 

</ItemTemplate>

Somethings not right with 'CategoryId' because it will 开发者_如何学Pythonwork if I take it out:

<aclass='MostPopularItemText'href='ProductDetails.aspx?productID=<%# Eval("ProductId") %>&&CategoryId=<%# Eval("CategoryId") %>'><%# Eval("ModelName") %></a><br/>    

to

<aclass='MostPopularItemText'href='ProductDetails.aspx?productID=<%# Eval("ProductId") %>'><%# Eval("ModelName") %></a><br/>  

Codebehind:

private void WriteAlsoPurchased(int currentProduct)

{

   using (CommerceEntities db = new CommerceEntities())

    {

       try

          {

            var v = db.SelectPurchasedWithProducts(currentProduct);

                   RepeaterItemsList.DataSource = v;

                   RepeaterItemsList.DataBind();

           }

       catch (Exception exp)

           {

            throw new Exception("ERROR: Unable to Write Also Purchased - " + exp.Message.ToString(), exp);  <------location where the exception is thrown

            }

      }

}

'SelectPurchasedWithProducts' Store Procedure:

ALTER PROCEDURE

dbo.SelectPurchasedWithProducts

@ProductID int

AS

SELECT TOP 5 

OrderDetails.ProductID,

Products.CategoryID,

Products.ModelName,



SUM(OrderDetails.Quantity) as TotalNum

FROM

    OrderDetails

INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID

WHERE

  OrderID IN 

(

/* This inner query should retrieve all orders that have contained the productID */

SELECT DISTINCT OrderID 

FROM OrderDetails

WHERE ProductID = @ProductID

)

AND

OrderDetails.ProductID != @ProductID 

GROUP BY

OrderDetails.ProductID, Products.CategoryID, Products.ModelName 

ORDER BY

TotalNum DESC

RETURN


Your property is named CategoryID not CategoryId

<%# Eval("CategoryId")  %>

Should read

<%# Eval("CategoryID")  %>


Some thoughts:

  • How about <%# Eval("Products.CategoryId") %>?

  • Are the two ampersands causing an issue? &&CategoryId=...

  • Also, try binding CategoryId outside of the link by itself and verify that the value outputs. Your code looks good to me that's why I have to wonder if it's just the way your link is structured.


Ok I think I got it, after updating the S Proc, I have to access my Model Browser Function, expand the EntityContainer, enter the Function Imports and click on Update button. I hope this helps those with either the

"Databinding: does not contain a property with the name 'xxx' error." or "A member of the type, 'xxx', does not have a corresponding column in the data reader with the same name."

after everything seem to be in place.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号