牛腩购物网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)

posted @ 2012-04-25 14:38  asp_net老友记  阅读(307)  评论(0编辑  收藏  举报