已经从表中取出了数据,代码如下:    private void Form1_Load(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS;user id=sa; password=sa; database=History;"))
            {
                SqlDataAdapter da = new SqlDataAdapter("select [ID],[UserName],[State],[Point],[Time]  from OnOff ", con);
                DataSet ds = new DataSet();
                da.Fill(ds, "OnOff");
                if (ds.Tables.Contains("OnOff"))
                {
                    dataGridView1.DataSource = ds.Tables["OnOff"];
                }
            }
        }我想要的功能是:  界面上4个按钮 ,"首页" "上一页" "下一页" "末页"。
  请问该功能该如何实现,水平有限,希望最好能给出代码。
多谢!!

解决方案 »

  1.   

    建议使用一个分页控件,刚刚已经有个人问了:
    http://topic.csdn.net/u/20100302/14/89daab72-2b33-4359-a14d-f559a17c9df5.html
      

  2.   


    using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=sa;database=Northwind"))
            {
                SqlDataAdapter sda = new SqlDataAdapter("select * from products", con);
                DataSet ds = new DataSet();
                int count, pageSize, currentPage;
                int.TryParse(Request.Form["pageSize"], out pageSize);
                pageSize = pageSize == 0 ? 10 : pageSize;
                int.TryParse(Request.Form["count"], out count);
                int.TryParse(Request.Form["pageNum"], out currentPage);
                int tempCount = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
                if (tempCount < currentPage)
                {
                    currentPage = tempCount;
                }
                sda.Fill(ds, (currentPage - 1) * pageSize, pageSize, "products");
                rp.DataSource = ds.Tables["products"].DefaultView;
                rp.DataBind();
                Response.Clear();
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                rp.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();
            }
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Sandy945/archive/2009/05/22/4208998.aspx
    Repeater 无刷新分页
    http://blog.csdn.net/Sandy945/archive/2009/05/22/4208998.aspx
      

  3.   

    存储过程分页写好了之后,好像关键也就是给存储过程传递正确的PageIndex,startRowIndex, maximumRows的问题吧。
      

  4.   

    PagedDataSource  分页http://topic.csdn.net/u/20091207/17/ac65d357-b669-4dc0-9221-8da344c52a34.html
      

  5.   

    在ASPX页面上添加如下代码即可: 
    [SettingsPager Mode="ShowPager"]
          [Summary AllPagesText="第{0}页 共{1}页 ({2} 条记录)" Text="第{0}页 共{1}页 ({2} 条记录)" /]
     [/SettingsPager]