关注技术

越学越无知

2.0中GridView中的分页

  string connectionString = ConfigurationManager.ConnectionStrings["xinProductsConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString=connectionString;
        string sqlstr = "select * from BoardRoom";
        SqlDataAdapter da=new SqlDataAdapter(sqlstr,conn);
        DataSet ds=new DataSet();

        try
        {
            da.Fill(ds, "word");
            PagedDataSource pg = new PagedDataSource();
            pg.DataSource = ds.Tables["Word"].DefaultView;
            pg.AllowPaging = true;
            pg.PageSize = 5;
            int currPage;
            if (Request.QueryString["page"] != null)

                currPage = Convert.ToInt32(Request.QueryString["page"]);
            else
                currPage = 1;

            pg.CurrentPageIndex = currPage - 1;

            LabelCurrpage.Text = "当前页:第" + currPage.ToString() + "页";
            LabelTotal.Text = "共有:" + pg.PageCount.ToString() + "页";

            HyperLinkFirstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page="+Convert.ToInt32(1);
            if (!pg.IsFirstPage)
                HyperLinkNextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToInt32(currPage - 1);
            if (!pg.IsLastPage)
                HyperLinkPrePage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToInt32(currPage + 1);
            HyperLinkLastPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToInt32(pg.PageCount);
          
            GridView1.DataSource = pg;
            GridView1.DataBind();

阅读更多
文章标签: dataset string null
个人分类: asp.net
上一篇Ajax 学习资源
下一篇GridView&ObjectDataSource新特性小记 懒人篇(一) 分页上路
想对作者说点什么? 我来说一句

GridView分页整套精美样式

2009年10月18日 18KB 下载

没有更多推荐了,返回首页

关闭
关闭