日期:2014-05-17 浏览次数:20420 次
/// <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.WriteLogFi