当前位置: 代码迷 >> ASP.NET >> 关于多条件查询、分页 数据源纷乱 please hlep me
  详细解决方案

关于多条件查询、分页 数据源纷乱 please hlep me

热度:5596   发布时间:2013-02-25 00:00:00.0
关于多条件查询、分页 数据源混乱 please hlep me .
如题 关于多条件查询、分页 数据源混乱。
先贴源码,再说问题。
C# code
/// <summary>        /// 分页 数据绑定        /// 还重载了PagedDataLoad方法,参数为List<Users>,作为数据源        /// </summary>        protected void PagedDataLoad()        {            try            {                //数据源                PagedDataSource Pgds = new PagedDataSource();                //数据源赋值                Pgds.DataSource = manager.QueryAll();                //设置允许分页                Pgds.AllowPaging = true;                //每页显示的行数                Pgds.PageSize = 5;                //显示总共页数                lblTotalPage.Text = Pgds.PageCount.ToString();                //当前页                int CurrentPage;                //请求页码为不为null设置当前页,否则为第一页                if (Request.QueryString["Page"] != null)                    CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);                else                    CurrentPage = 1;                //当前页索引为页码-1                Pgds.CurrentPageIndex = CurrentPage - 1;                //显示当前页码                lblCurrentPage.Text = CurrentPage.ToString();                //if(Pgds.PageCount)                //如果不是第一页,通过参数Page设置上一页为当前页-1,否则不显示连接                if (!Pgds.IsFirstPage)                {    //Request.CurrentExecutionFilePath为当前请求虚拟路径                    if (CurrentPage <= 0)                    {                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('不存在的页码!')", true);                        return;                    }                    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1);                                    }                //End If                //如果不是最后一页,通过参数Page设置下一页为当前页+1,否则不显示连接                if (!Pgds.IsLastPage)                {                    if (CurrentPage > Pgds.PageCount)                    {                        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('不存在的页码!')", true);                        return;                    }                    //Request.CurrentExecutionFilePath为当前请求虚拟路径                    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1);                }                //将当前页数保存到ViewState                //ViewState["page"] = CurrentPage.ToString();                //模板绑定数据源                  Repeater1.DataSource = Pgds;                Repeater1.DataBind();            }            catch (Exception ex)            {                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('" + ex.Message.ToString() + "')", true);                return;            }        }         /////////////多条件查询的查询按钮事件        protected void btnSend_Click(object sender, EventArgs e)        {                        if (txtID.Text.Trim() == "" && txtName.Text.Trim() == "" && txtRemark.Text.Trim() == "")            {                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('必须填其中一项!')", true);                PagedDataLoad();                return;            }            int id = 0;            try            {                if (txtID.Text.Trim() != "")                    id = Convert.ToInt32(txtID.Text.Trim());            }            catch (Exception ex)            {                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('ID应为大于0的自然整数,请重新输入!!')", true);                txtID.Text = "";                ExceptionManage.WriteLogFile(ex.ToString());                return;            }                        //从repeater中找到Timer控件,并停止异步回发。            Timer timer = new Timer();            for (int i = 0; i < Repeater1.Items.Count; i++)            {                timer = (Timer)Repeater1.Items[i].FindControl("Timer1");            }            timer.Enabled = false;            List<Users> list = manager.QueryList(id, txtName.Text, txtRemark.Text);            PagedDataLoad(list);        }/////////////////Timer_Tick 事件protected void Time1_Tick(object sender, EventArgs e)        {            PagedDataLoad();        }///////////////////删除按钮事件protected void BtnDel_Click(object sender, EventArgs e)        {            Button del = (Button)sender;            int id = Convert.ToInt32(del.CommandArgument);            int n = manager.Delete(id);            if (n == 0)            {                Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('删除失败!');", true);            }            else            {                Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('删除成功!');", true);            }            PagedDataLoad();        }