日期:2014-05-17  浏览次数:20430 次

AspNetPager控件做翻页,当从其他页返回到第一页时,出错,查询条件丢失,如何保存查询条件
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

           
             string 条件= " from info where 1=1";

        if (Request.Form["id"] != "")
        {........条件语句    }
        else
        {........条件语句    }
        string sqlStr = "select count(distinct(id)) as all_num " + 条件+"";

        if (Request.QueryString["page"] == null)
        {
            Session["sqlString"] = sqlString;
        }
        else
        {
            sqlString = Session["sqlString"].ToString();
        }
            SqlConnection conn = new SqlConnection(strCon); ;  //新建数据库连接对象,其中s是上面的连接字符串
   
            conn.Open();    //打开与数据库的连接
            SqlCommand cmd = new SqlCommand(sqlStr, conn);
            AspNetPager1.AlwaysShow = true;
            AspNetPager1.PageSize = 2;
            AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
            conn.Close();
            bind();

        }

    }
     protected void AspNetPager1_PageChanged(object sender, EventArgs e)  
        {
            bind();
        }  


    //绑定


    public void bind()
    {
        string 条件= " from info where 1=1";

        if (Request.Form["id"] != "")
        {........条件语句    }
        else
        {........条件语句    }
        if (Request.QueryString["page"] == null)
        {