DataTable dt = new DataTable();
        if(Request.QueryString["typeId"] != null)
        {
            int typeId = Convert.ToInt32(Request.QueryString["typeId"]);
            SqlParameter paramList = new SqlParameter("@pl_byProTypeId", SqlDbType.Int, 4);
            paramList.Value = typeId;
            using (SqlConnection connection = DataConnection.GetConnection())
            {
                dt = SQLHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "proc_pro_select_proByTypeId", paramList).Tables[0];
            }
        }
        else
        {
            using (SqlConnection connection = DataConnection.GetConnection())
            {
                dt = SQLHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "proc_pro_select").Tables[0];
            }
        }        ///分页代码
我设了一个datatable为公有的,然后用IF语句判断是否有产品类型ID传过来,来存储数据,然后再绑定到我的分页代码现在的问题是:
我首先访问了产品页面列出所有产品,产生了分页,然后我再点产品的类型,也产生了分页,当我点击类型的下一页,它不是连到同一类型的下一页,而是连去了所有产品的第二页这是什么问题呢?

解决方案 »

  1.   

    我以前也做过这样的,感觉麻烦的很,我最后用分页类做的,代码给你看看,自己觉得写的太烂了,不过效果是实现了,你好好润色下    public int Index
        {
            get 
            { 
                return (int)ViewState["Page"]; 
            }
            set 
            {
                ViewState["Page"] = value;
            }
        }    
        private void Databind(IList<LoginLog> dataSource,int count)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = dataSource;
            pds.AllowPaging = true;
            pds.PageSize = 10;
            pds.CurrentPageIndex = Index;
            ViewState["allPage"] = pds.PageCount;
            if (Index == 0)
            {
                this.imgPre.Visible = false;
                this.imgFrist.Visible = false;
            }
            else if (Index == pds.PageCount - 1)
            {
                this.imgNext.Visible = false;
                this.imgEnd.Visible = false;
            }
            if (count == 0)
            {
                this.lblCount.Text = "对不起,没有您要查询的记录!";
                this.imgPre.Visible = false;
                this.imgFrist.Visible = false;
                this.imgNext.Visible = false;
                this.imgEnd.Visible = false;
            }
            else if (count<=10)
        {
                this.lblCount.Text = "共 " + count + " 条数据 当前 " + (pds.CurrentPageIndex + 1) + "/" + pds.PageCount + " 页";
                this.imgPre.Visible = false;
                this.imgFrist.Visible = false;
                this.imgNext.Visible = false;
                this.imgEnd.Visible = false;
        }
            else
            {
                this.lblCount.Text = "共 " + count + " 条数据 当前 " + (pds.CurrentPageIndex + 1) + "/" + pds.PageCount + " 页";
            }
            this.GridView1.DataSource = pds;
            this.GridView1.DataBind();
        }
        //加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Page"] = 0;
                Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
            }
        }
            //搜索按钮
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["isClick"] = true;
            string bTime = this.txtBeginTime.Text.Trim();
            string eTime = this.txtEndTime.Text.Trim();
            if (LoginLogManager.CountALLByTime(bTime, eTime) > 2)
            {
                this.imgNext.Visible = true;
                this.imgEnd.Visible = true;
            }
            Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
        }
        //首页
        protected void imgFrist_Click(object sender, ImageClickEventArgs e)
        {
            this.imgNext.Visible = true;
            this.imgEnd.Visible = true;
            ViewState["Page"] = 0;
            if (Convert.ToBoolean(Session["isClick"]))
            {
                string bTime = this.txtBeginTime.Text.Trim();
                string eTime = this.txtEndTime.Text.Trim();
                Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
            }
            else
            {
                Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
            }
        }
        //上页
        protected void imgPre_Click(object sender, ImageClickEventArgs e)
        {
            if (Index > 0)
            {
                this.imgNext.Visible = true;
                this.imgEnd.Visible = true;
                Index--;
            }
            if (Convert.ToBoolean(Session["isClick"]))
            {
                string bTime = this.txtBeginTime.Text.Trim();
                string eTime = this.txtEndTime.Text.Trim();
                Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
            }
            else
            {
                Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
            }
        }
        //下一页
        protected void imgNext_Click(object sender, ImageClickEventArgs e)
        {
            if (Index >=0)
            {
                this.imgPre.Visible = true;
                this.imgFrist.Visible = true;
                Index++;
            }
            if (Convert.ToBoolean(Session["isClick"]))
            {
                string bTime = this.txtBeginTime.Text.Trim();
                string eTime = this.txtEndTime.Text.Trim();
                Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
            }
            else
            {
                Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
            }
        }    //末页
        protected void imgEnd_Click(object sender, ImageClickEventArgs e)
        {
            this.imgPre.Visible = true;
            this.imgFrist.Visible = true;
            Index = Convert.ToInt32(ViewState["allPage"])-1;        if (Convert.ToBoolean(Session["isClick"]))
            {
                string bTime = this.txtBeginTime.Text.Trim();
                string eTime = this.txtEndTime.Text.Trim();
                Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
            }
            else
            {
                Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
            }
        }        protected void btnGo_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(this.txtCount.Text)<=1)
            {
                Index = 0;
                this.imgNext.Visible = true;
                this.imgEnd.Visible = true;
            }
            else if (Convert.ToInt32(this.txtCount.Text) > Convert.ToInt32(ViewState["allPage"]) - 1)
            {
                Index = Convert.ToInt32(ViewState["allPage"]) - 1;
                this.imgPre.Visible = true;
                this.imgFrist.Visible = true;
            }
            else
            {
                Index = Convert.ToInt32(this.txtCount.Text) - 1;
                this.imgNext.Visible = true;
                this.imgEnd.Visible = true;
                this.imgPre.Visible = true;
                this.imgFrist.Visible = true;
            }
            Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
        }
      

  2.   

    试试AspNetPager
      

  3.   


    既然你的产品类别是靠QueryString保持的,那么你就要看看你使用的所谓分页机制(特别是当你使用第三方控件时)是否搞丢了这个url参数。
      

  4.   

    不知道你的具体页面设计,举个例子:假设左边是一个DataList来显示分类列表,右边使用GridView显示分类下的明细,那么右边的数据源(比如说是使用一个ObjectDataSource)的在设计页面上它的<SelectParameters>中必定有一项<asp:ControlParameter>是声明为自动匹配左边的DataList的SelectedValue属性的。如果这一项声明为<asp:QueryStringParameter>那就成了你的代码的那种问题了,它应该直截了当地声明为跟左边的DataList匹配,而不是跟QueryString匹配。
      

  5.   

    另外,你学asp.net最好学asp.net2.0的编程方法。那种只是asp.net1.1版本语法的一些书籍和“范例”,动不动就写一大堆代码,设计、修改和维护起来后期就很麻烦。你的这个程序应该几乎不用写代码就能完成。
      

  6.   

    Request.QueryString你第一次接收后   没有保存     就要每个分页都要传  类似 xxx.aspx?...typeid=..好好看看aspnetpager吧  人家作者都在这里了
      

  7.   


    先谢谢你了!你看看我这问题是不是这样造成的因为我是用Request.QueryString["typeId"] != null 来判断是否有值传过来
    如果有值我就用该值来做查询条件,再列出对应的产品
    没有值的就直接列出所有产品第一次加载的时候肯定是列出所有产品的,然后我再点左边的类型,是列出对应的产品,当我点击下一页的时候,因为我页面有刷新,所以造成Request.QueryString["typeId"] 这个值丢失了,就造成了下一页的内容变回了第一次加载时(也就是所有产品)第二页的内容,我觉得问题好像是这样了。另外请问你有学习asp.net2.0的网址吗!网上的教程很乱,会盲目学习的。谢谢!