点击商品展示按钮后线显示所有数据.然后在根据类别显示商品类别.这些都做出了了
 
  关键是我在点超链接显示所有数据的时候他显示的还是商品类别 而不是所有 该怎么解决啊...
 protected void Page_Load(object sender, EventArgs e)
  {
      if (!this.IsPostBack)
      {
          Bind();
      }
     
    #region==接收分页参数==
    if (Request.QueryString["page"] == null)
    {
      curPage = 1;
    }
    else
    {
      if (!curfunction.IsNum(Request.QueryString["page"].ToString()))
      {
        Javascript.ShowErr("参数错误");
      }
      else
      {
        curPage = int.Parse(Request.QueryString["page"].ToString());
        
      }
    }
    #endregion
    
    //产品种类
    if (Request.QueryString["typeId"] != null && curfunction.IsNum(Request.QueryString["typeId"].ToString()))
    {
      typeId = curfunction.checkStr(Request.QueryString["typeId"].ToString());
    }
    //搜索关键字
    if (Request.QueryString["keyword"] != null)
    {
      keyword = curfunction.checkStr(Request.QueryString["keyword"].ToString());
    }
    Bind();
    BindProduct(curPage, pagesize);
    
}
#region==得到所有商品==
private void Bind()
{
     string sql = "select * from ZZY_Product";     DataSet ds = sqlHelper.GetDataset(sql);
     GetProduct(ds, this.lb_product);//输出产品i
     Pagination(curPage, curPage);
     
}#region======得到产品========
private void BindProduct(int curPage, int pagesize)
  {
    int totalPage = 0;//总页数
    int totalCount = 0;//总记录数    string sqlStr = "";
      if (typeId != "")
      {
          sqlStr = "select count(*) from ZZY_Product where product_typeId=" + typeId + " or p_id=" + typeId + " or pp_id=" + typeId + " and product_name like '%" + keyword + "%'";
      }
      else
      {
        sqlStr = "select count(*) from ZZY_Product ";
      }
    totalCount = int.Parse(sqlHelper.GetValue(sqlStr)); //得到总记录数    //计算总页数
    if (totalCount % pagesize != 0)
    {
      totalPage = (totalCount / pagesize) + 1;
    }
    else
    {
      totalPage = totalCount / pagesize;
    }    
    string str = "";
    string whereStr = "";//查询条件
    if (typeId != "")
    {
        whereStr = "product_typeId =" + typeId + " or p_id=" + typeId + " or pp_id=" + typeId + " and product_name like '%" + keyword + "%'";
    }
    else
    {
        if (keyword != "") { whereStr = "product_name like '%" + keyword + "%'";}
    }
    //如果是第一页----第一页的sql与其它不同
    if (curPage == 1)
    {
      str = "select top " + pagesize + " *  from ZZY_Product where " + whereStr + " order by product_Id desc";
      if (typeId == "" && keyword == "") 
      {
          str = "select top " + pagesize + " *  from ZZY_Product order by product_Id desc";
      }
    }
    else
    {
      str = "select top " + pagesize + " *  from ZZY_Product where ( product_Id not in (select top " + (curPage - 1) * pagesize + " product_Id from ZZY_Product where " + whereStr + " order by product_Id desc)) and " + whereStr + " order by product_Id desc ";
      if (typeId == "" && keyword == "")
      {
          str = "select top " + pagesize + " *  from ZZY_Product where ( product_Id not in (select top " + (curPage - 1) * pagesize + " product_Id from ZZY_Product order by product_Id desc)) order by product_Id desc ";
      }
    }    DataSet ds = sqlHelper.GetDataset(str);
    GetProduct(ds, this.lb_product);//输出产品
    Pagination(totalCount, totalPage);//分页
  }
  #endregion
  #region =========输出产品=============
  private void GetProduct(DataSet ds, Label lb)
  {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
    if (ds.Tables[0].Rows.Count > 0)
    {
      int displayPerTR = 4; //每列显示产品数
      int rows = 0;//总行数
      int count = ds.Tables[0].Rows.Count;
      int k = 0;
      if (count % displayPerTR != 0)
      {
        rows = (count / displayPerTR) + 1;
      }
      else
      {
        rows = count / displayPerTR;
      }      sb.Append("<table width=\"650\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
      for (int j = 0; j < rows; j++)
      {
            sb.Append("<tr>");
            for (int i = 0; i < displayPerTR; i++)
            {
              if (k < count)
              {
                sb.Append("<td width=\"162\" height=\"120\" align=\"center\" valign=\"top\">");
                sb.Append("<table width=\"137\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                sb.Append("<tr>");
                sb.Append("<td height=\"112\" align=\"center\" valign=\"middle\" background=\"images/xgt_30.jpg\"><a href=productinfo.aspx?id=" + ds.Tables[0].Rows[k]["product_Id"].ToString() + " target=_blank><img src=\"" + ds.Tables[0].Rows[k]["product_smallPic"].ToString().Replace("~/", "") + "\" alt=" + ds.Tables[0].Rows[k]["product_name"].ToString() + " width=124 height=105  border=\"0\"/></a></td>"); 
                sb.Append("</tr>");
                sb.Append("<tr>");
                sb.Append("<td align=\"center\" valign=\"middle\" class=\"b6\"><a href=productinfo.aspx?id=" + ds.Tables[0].Rows[k]["product_Id"].ToString() + " target=_blank>" + curfunction.CutTitle(ds.Tables[0].Rows[k]["product_name"].ToString(), 12) + "</a></td>");
                sb.Append("</tr>");
                sb.Append("</table>");
                sb.Append("</td>");                k++;
              }
              else
              {
                sb.Append("<td width=\"162\" align=\"center\" valign=\"top\">");
                sb.Append("</td>");
              }
            }
           sb.Append("</tr>");
      }
      sb.Append("</table>");
    }
    else
    {
      sb.Append("<font size=1>暂无任何数据</font>");
    }    lb_product.Text = sb.ToString();
  }
  #endregion    #region========控制分页===============
  private void Pagination(int totalCount, int totalPage)
  {
    string firstPagelinkStr = "";
    string endPagelinkStr = "";
    string lastPagelinkStr = "";
    string nextPagelinkStr = "";      if (typeId != "")
      {
        firstPagelinkStr = "product.aspx?page=1&typeId=" + typeId + "&keyword=" + keyword + "";
        endPagelinkStr = "product.aspx?page=" + totalPage + "&typeId=" + typeId + "&keyword=" + keyword + "";
        lastPagelinkStr = "product.aspx?page=" + (curPage - 1) + "&typeId=" + typeId + "&keyword=" + keyword + "";
        nextPagelinkStr = "product.aspx?page=" + (curPage + 1) + "&typeId=" + typeId + "&keyword=" + keyword + "";
      }
      else
      {
        firstPagelinkStr = "product.aspx?page=1";
        endPagelinkStr = "product.aspx?page=" + totalPage + "";
        lastPagelinkStr = "product.aspx?page=" + (curPage - 1) + "";
        nextPagelinkStr = "product.aspx?page=" + (curPage + 1) + "";
      }    string pageInfo = "共<span>" + totalCount.ToString() + "</span>条记录 <span>" + pagesize.ToString() + "</span>条/页 共<span>" + totalPage.ToString() + "</span>页 当前 <span>" + curPage.ToString() + "/" + totalPage.ToString() + "</span>页 ";    if (curPage == 1)
    {
      //如果是第一页
      this.lb_paging.Text = pageInfo + "<a  href=\"" + nextPagelinkStr + "\">下页</a> <a  href=\"" + endPagelinkStr + "\">尾页</a>";
    }
    else if (curPage == totalPage)
    {
      this.lb_paging.Text = pageInfo + "<a href=\"" + firstPagelinkStr + "\">首页</a> <a href=\"?typeId=" + lastPagelinkStr + "\">上页</a>";
    }
    else
    {
      this.lb_paging.Text = pageInfo + "<a href=\"" + firstPagelinkStr + "\">首页</a> <a href=\"?typeId=" + lastPagelinkStr + "\">上页</a> <a  href=\"" + nextPagelinkStr + "\">下页</a> <a  href=\"" + endPagelinkStr + "\">尾页</a>";
    }
    if (totalPage == 1 || totalPage == 0)
    {
      this.lb_paging.Text = pageInfo;
    }
  }  #endregion
  #endregion
}

解决方案 »

  1.   


    if (Request.QueryString["typeId"] != null && curfunction.IsNum(Request.QueryString["typeId"].ToString()))
      {
      typeId = curfunction.checkStr(Request.QueryString["typeId"].ToString());
      }///else???
      

  2.   

    "select count(*) from ZZY_Product where product_typeId=" + typeId + " or p_id=" + typeId + " or pp_id=" + typeId + " and product_name like '%" + keyword + "%'"太乱,没看明白
    不过上面的SQL是有点问题的
    "select count(*) from ZZY_Product where (product_typeId=" + typeId + " or p_id=" + typeId + " or pp_id=" + typeId + ") and product_name like '%" + keyword + "%'"
    加括号和不加括号显然不一样
      

  3.   

    LS正解SQL有些问题代码太长,没仔细看勒。
      

  4.   

    代码太乱
    分页aspnetpager控件
    单步跟踪sqlStr 
      

  5.   

    代码这样看起来太乱了.重新用C#code发下吧