大家好,我需要在此建议书上寻求帮助,我正在尝试将其添加到我的网站中,这是代码. [英] Hi all, I need some help on this Recommendation i'm trying to add to my web site, here is the code.
本文介绍了大家好,我需要在此建议书上寻求帮助,我正在尝试将其添加到我的网站中,这是代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到此错误的部分是:
The part I''m getting this error on is:
// fill shopping cart controls with data
private void PopulateControls()
{
// Display product recommendations
recommendations.LoadCartRecommendations();
}
错误是:名称建议在当前上下文中不存在.
The error is: The name recommendations does not excist in the current context.
推荐答案
很明显,尚未创建推荐对象或您尚未为您的项目添加必需的引用.
Well obviously the recommendations object has not been created or you have not added a required reference to your project.
感谢您回答Mark.我是ASP.NET和C#的新手,并且正在关注本书,因此我不确定它在哪里缺少此建议.
这是Recommendion Web控件的代码:
控制
Thanks for you answer Mark. I''m new to ASP.NET and C#, and I''m following this Book so I''m not sure where it''s missing this recommendtion.
This is the code for the Recommendion Web control:
Control
<uc1:productrecommendations id="recommendations" runat="server" xmlns:uc1="#unknown" />
using System;
using System.Data;
public partial class UserControls_ProductRecommendations : System.Web.UI.UserControl
{
public void LoadProductRecommendations(string productId)
{
// display product recommendations
DataTable table = CatalogAccess.GetRecommendations(productId);
if (table.Rows.Count > 0)
{
list.ShowHeader = true;
list.DataSource = table;
list.DataBind();
}
}
public void LoadCartRecommendations()
{
// display product recommendations
DataTable table = ShoppingCartAccess.GetRecommendations();
if (table.Rows.Count > 0)
{
list.ShowHeader = true;
list.DataSource = table;
list.DataBind();
}
}
}
HTML:
The HTML:
<![CDATA[<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductRecommendations.ascx.cs" Inherits="UserControls_ProductRecommendations" %>]]>
<asp:datalist id="list" runat="server" showheader="false" xmlns:asp="#unknown">
<HeaderStyle CssClass=" RecommendationsHead " />
<HeaderTemplate>
We also recommend:
</HeaderTemplate>
<itemtemplate>
<a class="RecommendationLabel" href="<%# Link.ToProduct(Eval("ProductID").ToString())%>">
<%# Eval("Name") %>
</a>
<%# Eval("Description") %>
</itemtemplate>
</asp:datalist>
数据库代码:
Code for the Database:
// gets product recommendations
public static DataTable GetRecommendations(string productId)
{
// get a configured DbCommand object
DbCommand comm = GenericDataAccess.CreateCommand();
// set the stored procedure name
comm.CommandText = "CatalogGetProductRecommendations";
// create a new parameter
DbParameter param = comm.CreateParameter();
param.ParameterName = "@ProductID";
param.Value = productId;
param.DbType = DbType.Int32;
comm.Parameters.Add(param);
// create a new parameter
param = comm.CreateParameter();
param.ParameterName = "@DescriptionLength";
param.Value = BalloonShopConfiguration.ProductDescriptionLength;
param.DbType = DbType.Int32;
comm.Parameters.Add(param);
// execute the stored procedure
return GenericDataAccess.ExecuteSelectCommand(comm);
}
购物车代码推荐:
Code for the Shopping cart Recommendation:
// gets product recommendations for the shopping cart
public static DataTable GetRecommendations()
{
// get a configured DbCommand object
DbCommand comm = GenericDataAccess.CreateCommand();
// set the stored procedure name
comm.CommandText = "CatalogGetCartRecommendations";
// create a new parameter
DbParameter param = comm.CreateParameter();
param.ParameterName = "@CartID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
comm.Parameters.Add(param);
// create a new parameter
param = comm.CreateParameter();
param.ParameterName = "@DescriptionLength";
param.Value = PoshandDanglesConfiguration.ProductDescriptionLength;
param.DbType = DbType.Int32;
comm.Parameters.Add(param);
// execute the stored procedure
return GenericDataAccess.ExecuteSelectCommand(comm);
Product.aspx的代码
Code for the Product.aspx
// Fill the control with data
private void PopulateControls(ProductDetails pd)
{
// Display product recommendations
string productId = pd.ProductID.ToString();
recommendations.LoadProductRecommendations(productId);
谢谢!
thanks!
这篇关于大家好,我需要在此建议书上寻求帮助,我正在尝试将其添加到我的网站中,这是代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文