Web层
<asp:DataList ID="DataList1" runat="server" RepeatColumns="2" RepeatDirection="Horizontal" DataKeyField="GoodsID" >
<ItemTemplate>
<div id="ny_order_bg">
<div id="left_pic"> <a href="GoodsInfo.aspx?GoodsID= <%#Eval("GoodsID")%>"/> <img src=' <%#Eval("GoodsPic")%>' width="80" border="0" alt="" /> </div>
<div id="pic_info">
<div id="info_tt"> <a href="GoodsInfo.aspx?GoodsID= <%#Eval("GoodsID")%>"/> <%#Eval("GoodsName")%> <br /> <%#Eval("EnglishName")%> </div>
<div id="info_nr">产品规格:酒精度 <%#Eval("SpecName")%>(V/V) <br />市场价: <span class="red"> <%#Eval("MarketPrice")%> </span>元/瓶 会员价: <span class="red"> <%#Eval("MemberPrice")%> </span>元/瓶 </div>
<div id="info_bottom"> <asp:ImageButton ID="imgShoppingCart" runat="server" OnClick="imgShoppingCart_Click" ImageUrl="~/images/order.gif" CommandArgument=' <%#Eval("GoodsID")%>' /> <asp:HiddenField ID="GID" runat="server" /> </div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
代码:
protected void imgShoppingCart_Click(object sender, ImageClickEventArgs e)
{
if (Session["UID"] == null)
{
ControlControls();
// Response.Write(" <script language=javascript>alert('对不起,你没有登陆,不能购买物品');window.location='Login.aspx' </script>");
}
else
{
UID = int.Parse(Session["UID"].ToString());
ShopCartClass sc = new ShopCartClass();
ShopCartManage shopCartManage = new ShopCartManage();
string ID = Request.QueryString["GoodsID"];//取不出值,为空
//gi = goodsInfoManage.SGoodInfo(int.Parse(ID));
//sc.GoodsID = gi.GoodsID;
sc.SumPrice = decimal.Parse(Request.QueryString["SumPrice"]);
sc.UID = UID;
int result = shopCartManage.AddShopCart(sc);
if (result == 1)
{ Response.Redirect("ShopCart.aspx");
}
else
{
Response.Write(" <script type='text/javascript'>alert('操作失败!');history.back(); </script>");
}
}
} 绑定的代码:
private void GridViewBind()
{
AspNetPager1.RecordCount = goodsInfoManage.InfoCount(gi);
DataList1.DataSource = goodsInfoManage.SGoodsInfo(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
DataList1.DataBind();
} 存储过程:
public List <GoodsInfo> SGoodsInfo(int pageIndex, int pageSize)
{
SqlParameter[] sqlParameters = {
new SqlParameter("@pageIndex",SqlDbType.Int),
new SqlParameter("@pageSize",SqlDbType.Int)
};
sqlParameters[0].Value = pageIndex;
sqlParameters[1].Value = pageSize;
List <GoodsInfo> list = new List <GoodsInfo>();
SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.StoredProcedure, "User_SGoodsInfo", sqlParameters);
while (reader.Read())
{
GoodsInfo gi = new GoodsInfo();
gi.GoodsID = int.Parse(reader["GoodsID"].ToString());
gi.GoodsName = reader["GoodsName"].ToString();
gi.EnglishName = reader["EnglishName"].ToString();
gi.SpecName = reader["TypeName"].ToString();
gi.GoodsPic = reader["GoodsPic"].ToString();
gi.MarketPrice = decimal.Parse(reader["MarketPrice"].ToString());
gi.MemberPrice = decimal.Parse(reader["MemberPrice"].ToString());
list.Add(gi);
}
reader.Dispose();
return list;
}
public int InfoCount(GoodsInfo gi)
{
return Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.StoredProcedure, "proc_GetGoodsCount", null).ToString());
}
<asp:DataList ID="DataList1" runat="server" RepeatColumns="2" RepeatDirection="Horizontal" DataKeyField="GoodsID" >
<ItemTemplate>
<div id="ny_order_bg">
<div id="left_pic"> <a href="GoodsInfo.aspx?GoodsID= <%#Eval("GoodsID")%>"/> <img src=' <%#Eval("GoodsPic")%>' width="80" border="0" alt="" /> </div>
<div id="pic_info">
<div id="info_tt"> <a href="GoodsInfo.aspx?GoodsID= <%#Eval("GoodsID")%>"/> <%#Eval("GoodsName")%> <br /> <%#Eval("EnglishName")%> </div>
<div id="info_nr">产品规格:酒精度 <%#Eval("SpecName")%>(V/V) <br />市场价: <span class="red"> <%#Eval("MarketPrice")%> </span>元/瓶 会员价: <span class="red"> <%#Eval("MemberPrice")%> </span>元/瓶 </div>
<div id="info_bottom"> <asp:ImageButton ID="imgShoppingCart" runat="server" OnClick="imgShoppingCart_Click" ImageUrl="~/images/order.gif" CommandArgument=' <%#Eval("GoodsID")%>' /> <asp:HiddenField ID="GID" runat="server" /> </div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
代码:
protected void imgShoppingCart_Click(object sender, ImageClickEventArgs e)
{
if (Session["UID"] == null)
{
ControlControls();
// Response.Write(" <script language=javascript>alert('对不起,你没有登陆,不能购买物品');window.location='Login.aspx' </script>");
}
else
{
UID = int.Parse(Session["UID"].ToString());
ShopCartClass sc = new ShopCartClass();
ShopCartManage shopCartManage = new ShopCartManage();
string ID = Request.QueryString["GoodsID"];//取不出值,为空
//gi = goodsInfoManage.SGoodInfo(int.Parse(ID));
//sc.GoodsID = gi.GoodsID;
sc.SumPrice = decimal.Parse(Request.QueryString["SumPrice"]);
sc.UID = UID;
int result = shopCartManage.AddShopCart(sc);
if (result == 1)
{ Response.Redirect("ShopCart.aspx");
}
else
{
Response.Write(" <script type='text/javascript'>alert('操作失败!');history.back(); </script>");
}
}
} 绑定的代码:
private void GridViewBind()
{
AspNetPager1.RecordCount = goodsInfoManage.InfoCount(gi);
DataList1.DataSource = goodsInfoManage.SGoodsInfo(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
DataList1.DataBind();
} 存储过程:
public List <GoodsInfo> SGoodsInfo(int pageIndex, int pageSize)
{
SqlParameter[] sqlParameters = {
new SqlParameter("@pageIndex",SqlDbType.Int),
new SqlParameter("@pageSize",SqlDbType.Int)
};
sqlParameters[0].Value = pageIndex;
sqlParameters[1].Value = pageSize;
List <GoodsInfo> list = new List <GoodsInfo>();
SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.StoredProcedure, "User_SGoodsInfo", sqlParameters);
while (reader.Read())
{
GoodsInfo gi = new GoodsInfo();
gi.GoodsID = int.Parse(reader["GoodsID"].ToString());
gi.GoodsName = reader["GoodsName"].ToString();
gi.EnglishName = reader["EnglishName"].ToString();
gi.SpecName = reader["TypeName"].ToString();
gi.GoodsPic = reader["GoodsPic"].ToString();
gi.MarketPrice = decimal.Parse(reader["MarketPrice"].ToString());
gi.MemberPrice = decimal.Parse(reader["MemberPrice"].ToString());
list.Add(gi);
}
reader.Dispose();
return list;
}
public int InfoCount(GoodsInfo gi)
{
return Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionString, CommandType.StoredProcedure, "proc_GetGoodsCount", null).ToString());
}
解决方案 »
- 关于vs2008的汉化
- 寻求一个正则表达式(关于网址)
- 为什么使用Response.Redirect("WebForm1.aspx")会页面跳转,回到客户端为什么会再次请求啊,搞不懂了?
- 大家帮帮忙
- 急:请教一个asp.net中使用javascript弹出窗口的问题
- 这种模式是如何实现的?
- Panel设置了横向滚动条,如何在js代码里取消呢?
- Could not load type 'Dottext.Web.SkinList',可我实在声明了这个类啊??????
- sstab 的属性
- vb+asp.net中的datagrid分页遇到问题?附代码
- vs 2005网站的发布
- 关于在对HTML的meta标记赋值的问题
ImageButton ibnButton = sender as ImageButton;
string ID = ibnButton.CommandArgument;
Datalist1.items[i].findControl("imgShoppingCart"))