页面头部控件的代码实现(UserContro\HeaderMenu.ascx.cs):
private void Page_Load(object sender, System.EventArgs e)
{ showButton();
}
void showButton()
{ //是否是匿名用户
if (Request.IsAuthenticated != true)
{ //登录用户区域不可见
areaLoggedIn.Visible = false;
//匿名用户区域可见
areaLoggedOut.Visible = true;
}
else
{ areaLoggedIn.Visible = true;
areaLoggedOut.Visible = false;
}
}
商品分类导航控件的代码实现(UserControl\CategoryList.ascx.cs):
private void Page_Load(object sender, System.EventArgs e)
{ string selectionID = Request.Params["selection"];
if ( selectionID != null)
{ MyList.SelectedIndex = Int32.Parse(selectionID);
}
MyList.DataSource = BLL.Product.GetCategoryList();
MyList.DataBind();
}
热门商品列表控件的代码实现(UserControl\PopularProduct.ascx.cs):
private void Page_Load(object sender, System.EventArgs e)
{ PopularList.DataSource = BLL.Product.GetPopularProduct();
PopularList.DataBind(); }
新到商品控件的代码实现(UserControl\NewProducts.ascx.cs):
private void Page_Load(object sender, System.EventArgs e)
{ NewList.DataSource = BLL.Product.GetNewProductsList();
NewList.DataBind();
}
eshop首页控件的实现代码(default.aspx.cs):
public class _default : System.Web.UI.Page
{ private void Page_Load(object sender, System.EventArgs e)
{ // 在此处放置用户代码以初始化页面
}
}
2、商品信息模块的实现:
商品信息模块共包含如下的页面:分类显示商品、商品详细信息、商品搜索结果,其代码实现如下:
分类显示商品的代码实现:
Product类,方法GetProductsByCategory():
public static SqlDataReader GetProductsByCategory(int categoryId, int pageSize, int pageIndex)
{ SqlParameter[] para = { new SqlParameter("@CategoryId", categoryId),
new SqlParameter("@pageSize", pageSize),
new SqlParameter("@pageIndex", pageIndex)
};
return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
CommandType.StoredProcedure, "GetProductByCategory", para);
}
(productlist.aspx.cs)代码如下:
private static int PageSize = 5;
private void Page_Load(object sender, System.EventArgs e)
{ if (!Page.IsPostBack)
{ //显示第一页的记录
ShowResult(0, PageSize);
}
}
void ShowResult(int pageIndex, int pageSize)
{ //绑定Repeater控件
products.DataSource = BLL.Product.GetProductsByCategory(int.Parse(Request.QueryString["categoryId"]), pageSize, pageIndex);
products.DataBind();
//调用Product类中的方法获得该类商品的总数
int resultCount = BLL.Product.GetProductCountByCategory(int.Parse(Request.QueryString["categoryId"]));
int count;
//如果查询结果总数是页大小的整数倍
if (resultCount%PageSize == 0)
{ count = resultCount/PageSize;
PageCount.Text = count.ToString();
}
else
{ count = resultCount/PageSize+1;
PageCount.Text = count.ToString();
}
page.Items.Clear();
//绑定页码到DropDownList控件
www.751com.cn
page.SelectedIndex = pageIndex;
}
private void page_SelectedIndexChanged(object sender, System.EventArgs e)
{
ShowResult(page.SelectedIndex, PageSize);
}
显示商品详细信息的代码实现:
(productInfo.aspx.cs)代码如下:
private void Page_Load(object sender, System.EventArgs e)
{if (!Page.IsPostBack)
{ ShowProductInfo(); }
}
void ShowProductInfo()
{ //获取Get方式传递的ProductId参数的值
int productId = int.Parse(Request["ProductId"]);
//获取某个商品的详细信息
BLL.ProductDetails pro = BLL.Product.GetProductInfo(productId);
//商品是否存在
if (pro == null)
{ lblSearchResults.Text = "没有这个商品";
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>