zoukankan      html  css  js  c++  java
  • 牛腩购物网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)

  • 相关阅读:
    SQLite 的连接串
    输入数组长度大于此表中的列数
    MVC3.0入门学习笔记页面传值ViewData
    MVC3.0入门学习笔记页面传值TempData
    在控制台程序中显示进度
    WCF学习笔记(1) 一个简单的wcf实例
    webBrowser 操作无ID元素
    webBrowser 设置文本框
    cookie总结
    checkbox是否被选择
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/2469797.html
Copyright © 2011-2022 走看看