购物网第三阶段总结笔记4:新品上架页面和特价商品页面

本文详细介绍了如何在电子商务网站中实现新品上架与特价商品页面的商品显示、排序及加入收藏功能,包括页面布局、数据库操作及后台逻辑实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【一】建立页面:newpro.aspx

(1):把数据库中新品上市的商品显示到页面中:

aspx代码:

               <table width="100%" border="0">
                    <tr>
                        <td height="35" bgcolor="#CCCCCC" style="font-weight: bold; padding-left: 10px;">
                            <img src="images/dot_03.gif" width="9" height="9" />
                            新品上架
                        </td>
                    </tr>
                    <tr>
                        <td height="35" align="right" style="padding-right: 20px; border-bottom: 1px #999999 solid;">
                            选择查看方式:
                            <select name="select">
                                <option>按商品关注度排序</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Repeater ID="rep" runat="server">
                            <ItemTemplate>
                             <div class="proitem">
                                <div class="proitem_img">
                                    <a href='pro.aspx?id=<%#Eval("id") %>' title='<%#Eval("proname") %>'>
                                        <img src='upload/<%#Eval("proimg") %>' width="85" height="105" /></a>
                                </div>
                                <div class="proitem_right">
                                    <div>
                                        市场价:<span class="delfont">¥<%#Eval("marketprice") %></span></div>
                                    <div>
                                        会员价:<span class="redfont">¥<%#Eval("memberprice") %></span></div>
                                    <div>
                                        <a href="#">
                                            <img src="images/gm.gif" /></a></div>
                                    <div>
                                        <a href="#">
                                            <img src="images/shc.gif" /></a></div>
                                </div>
                            </div>
                            </ItemTemplate>
                            </asp:Repeater>
                           

                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                           <webdiyer:AspNetPager ID="anp" runat="server"  FirstPageText="首页" 
                                LastPageText="尾页" NextPageText="下一页" NumericButtonCount="5" 
                                PrevPageText="上一页" 
                                CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条" 
                                PageSize="5" ShowCustomInfoSection="Left" AlwaysShow="true" onpagechanged="anp_PageChanged">
                            </webdiyer:AspNetPager>
                        </td>
                    </tr>
                </table>


cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class newpro : System.Web.UI.Page
    {
        MyShop.DAL.ProductDAO dao = new MyShop.DAL.ProductDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                anp.RecordCount = dao.CalcCount(GetCond());
                BindRep();
            }
        }

        //绑定数据
        private void BindRep()
        {
            rep.DataSource = dao.GetList("*", "createDate", "desc", anp.PageSize, anp.CurrentPageIndex, GetCond());
            rep.DataBind();
        }

        //获取条件
        private string GetCond()
        {
            string cond = "isxp=1";

            return cond;
        }
        //分页
        protected void anp_PageChanged(object sender, EventArgs e)
        {

            BindRep();
        }
    }
}



(2):商品排序
aspx代码:

注意添加: AutoPostBack="true"

                    <tr>
                        <td height="35" align="right" style="padding-right: 20px; border-bottom: 1px #999999 solid;">
                            选择查看方式:
                            <asp:DropDownList ID="ddlorder" runat="server">
                            <asp:ListItem Text="↓按上架时间降序排列" Value="0"></asp:ListItem>
                            <asp:ListItem Text="↑按上架时间升序排列" Value="1"></asp:ListItem>
                            <asp:ListItem Text="↓按商品会员价格降序排列" Value="2"></asp:ListItem>
                            <asp:ListItem Text="↑按商品会员价格升序排列" Value="3"></asp:ListItem>                           
                            </asp:DropDownList>
                        </td>
                    </tr>

cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class newpro : System.Web.UI.Page
    {
        MyShop.DAL.ProductDAO dao = new MyShop.DAL.ProductDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                anp.RecordCount = dao.CalcCount(GetCond());
                BindRep();
            }
        }

        //绑定数据
        private void BindRep()
        {
            string order = "createDate";
            string ordertype = "desc";
            switch (ddlorder.SelectedValue)
            {
                case "0":
                    order = "createDate";
                    ordertype = "desc";
                    break;
                case "1":
                    order = "createDate";
                    ordertype = "asc";
                    break;
                case "2":
                    order = "memberprice";
                    ordertype = "desc";
                    break;
                case "3":
                    order = "memberprice";
                    ordertype = "asc";
                    break;
                default:
                    break;
            }
            rep.DataSource = dao.GetList("*", order, ordertype, anp.PageSize, anp.CurrentPageIndex, GetCond());
            rep.DataBind();
        }

        //获取条件
        private string GetCond()
        {
            string cond = "isxp=1";

            return cond;
        }
        //分页
        protected void anp_PageChanged(object sender, EventArgs e)
        {

            BindRep();
        }

        //选择排序方式
        protected void ddlorder_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindRep();
        }
    }
}


(3):实现加入收藏按钮【结合购物网第三阶段总结笔记6】

aspx代码:

 <asp:LinkButton ID="LinkButton1" OnClick="Favorite" CommandArgument='<%#Eval("id") %>' runat="server">
<img src="images/shc.gif" />
</asp:LinkButton>

cs代码:

  //加入收藏
        protected void Favorite(object sender, EventArgs e)
        {
            string proid = (sender as LinkButton).CommandArgument;
            MyShop.DAL.FavoriteDAO dao = new MyShop.DAL.FavoriteDAO();
            int y = dao.CalcCount("username='"+User.Identity.Name+"' and proid="+proid);
            if (y!=0)
            {
                 Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('该商品您已经收藏过!')</script>");
                 return;
            }
            int x = dao.CalcCount("username='"+User.Identity.Name+"'");
            if (x==10)
            {
                 Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('您的收藏夹已满!')</script>");
                 return;
            }
            else
            {
                dao.Add(new MyShop.Model.Favorite() { 
                proid=int.Parse(proid),
                createDate=DateTime.Now,
                username=User.Identity.Name
                });


                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MsgBox", "<script>alert('收藏商品成功!')</script>");
            }
                
        }


 【二】:特价商品页面:tejiapro.aspx,和新品上架一摸一样,这部分视频不用看,笔记省略。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值