zoukankan      html  css  js  c++  java
  • 使用AspNetPager分页控件对动态查询的结果进行Url分页

    看了 aspnetpager分页控件的url分页的情况下根据查询结果动态分页的例子 也照着做了一下,大体上的思路是这样子的

    点击查询按钮时

     protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("UserLists.aspx?Name=" + txtName.Text);

           
                sb.Append("&Sex=" + ddlSex.SelectedValue); //根据输入的值和选择的条件拼接Url
           
            
            Response.Redirect(sb.ToString());
        }

    在Page_Load中 :

     protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            //    BindType();
            //}
           
           if(Request["Name"] !=null && Request["Name"] != "")
            {
                str.Append("UserName like '%");
                str.Append(Request["Name"]+"%'");

            }

           if (Request["Sex"] !=null && Request["Sex"]!="")
           {
               str.Append(" and UserSex= ");
               str.Append(Request["Sex"]);
           }
          
           

           AspNetPager1.RecordCount = GetRecordCount(str.ToString()); //根据查询条件查询出总的记录条数


        }

    由于是url分页 所以不用绑定数据,直接在AspNetPager1_PageChanging 中绑定数据

     protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            int cpage = 0;
            if (Request.QueryString["page"] != null)
            {
                cpage = Convert.ToInt32(Request.QueryString["page"].ToString());
            }
            else
            {
                cpage = 1;
            }
            int rowscount = 0;
            txtName.Text = Request["Name"];
            ddlSex.SelectedValue = Request["Sex"]; //显示查询条件

            GridView1.DataSource = news(str.ToString(), "UserID", cpage, 10, out rowscount);
            GridView1.DataBind();
          
        }

  • 相关阅读:
    AngularJS in Action读书笔记4(实战篇)——创建Statistic模块
    AngularJS in Action读书笔记3——走近Services
    AngularJS in Action读书笔记2——view和controller的那些事儿
    AngularJS in Action读书笔记1——扫平一揽子专业术语
    Nodejs学习笔记(四)——支持Mongodb
    Nodejs学习笔记(三)——一张图看懂Nodejs建站
    Nodejs学习笔记(二)——Eclipse中运行调试Nodejs
    Nodejs学习笔记(一)——初识Nodejs
    Unity Shader 获取模型空间坐标
    Unity Shader 修改自定义变量的值
  • 原文地址:https://www.cnblogs.com/zhiqiu/p/2843404.html
Copyright © 2011-2022 走看看