• 牛腩购物网31:产品搜索的制作,投票的制作,投票的div的长度


    搜索前台:

    关键字:<asp:TextBox ID="txtKey" runat="server"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 <asp:LinkButton ID="lbtnSearch" runat="server" OnClick="lbtnSearch_Click">搜索</asp:LinkButton>

     

    后台:

    //搜索,记得要对搜索的字符进行转码
            protected void lbtnSearch_Click(object sender, EventArgs e)
            {
                string key = txtKey.Text.Trim();
                if (key.Length == 0)
                {
                    Utility.Tool.alert("关键字不能为空", this.Page);
                    return;
                }
                else
                {
                   key=Server.UrlEncode(key);
                   Response.Redirect("/prolist.aspx?key=" + key);
                }
            }

     

    搜索的页面:

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    string caid = Request.QueryString["caid"];
                    int x;
                    if (int.TryParse(caid, out x))
                    {
                        anp.RecordCount = ptdao.CalcCount(getCond());
                        BindRep();
                    }
                    string key = Request.QueryString["key"];
                    if (!string.IsNullOrEmpty(key))
                    {
                        anp.RecordCount = ptdao.CalcCount(getCond());
                        BindRep();
                    }
                    //else
                    //{
                    //    Response.Write("参数传入错误");
                    //    Response.End();
                    //}
                }
            }

     

    private void BindRep()
            {
                string order = "createdate";
                string ordertype = "desc";
    
                switch (ddlOrder.SelectedValue)
                {
                    case "0":
                        order = "createdate"; ordertype = "asc";  //升序,从小到大  
                        break;
                    case "1":
                        order = "createdate"; ordertype = "desc"; //降序
                        break;
                    case "2":
                        order = "memberprice"; ordertype = "asc";
                        break;
                    case "3":
                        order = "memberprice"; ordertype = "desc";
                        break;
                    default:
                        break;
                }
                rep.DataSource = ptdao.GetList("*", order, ordertype, anp.PageSize, anp.CurrentPageIndex, getCond());
                rep.DataBind();
            }
            //获取条件
            private string getCond()
            {
                string cond = "";
    
                //这里要先判断传过来的关键字查询
                string key = Request.QueryString["key"];
                if (!string.IsNullOrEmpty(key))
                {
                    key = Server.UrlDecode(key);
                    key = Utility.Tool.GetSafeSQL(key);
                    cond = "proname like '%"+key+"%'";
                    return cond;
                }
    
                string caid = Request.QueryString["caid"];
                    int x;
                if (int.TryParse(caid, out x))
                {
                    cond += "caid=" + x; //这里还是有错的,因为只是求出了一个类别的,但是假如这是个大类的,那么大类以下的没有显示出来
                }
                return cond;
            }

    投票表:

    shop_vote:id,create,ip,vote

    投票的长度,假设我们把投票用2个 div 来显示, 完整的长度是250 ,满意的部分我们用 绿色,不满意就用蓝色

    满意票为4票:      那么 满意票的DIV的长度就为 250*(4/5)

    不满意票数为1票:  不满意的div的长度为    250*(1/5)

  • 相关阅读:
    牛客(47)求1+2+3+...+n
    牛客(48)不用加减乘除做加法
    【推荐】可编程的热键 AutoHotkey
    【Web】js 简单动画,犯了低级错误
    【分享】JDK8u241 win x64度盘下载
    【Web】开始学Web开发!
    【数组】深析 “数组名称”
    【基础向】浅析 "多(二)维数组" 的三种引用方法
    【一个小错误】通过数组指针引用数组成员
    【网络通信教程】windows 下的 socket API 编程(TCP协议)
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/2469797.html
Copyright © 2020-2023  润新知