可以进行sql语句进行设置:
   
   1.先新建一个窗体,一个DataGridView控件、两个label控件、两个Button控件
   2.代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient; namespace _2012_4_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static string str = "server=.;database=shuDB;uid=sa;pwd=accp";
SqlConnection conn = new SqlConnection(str);
DataSet set = new DataSet();
SqlDataAdapter adapter; int index = ; //sql语句中的索引
int yeshu = ; //下一页显示的页数
int sum = ; //总页码 //加载前6行数据
private void Form1_Load(object sender, EventArgs e)
{
this.label1.Text = "第" + yeshu.ToString() + "页";
string sql = @"select top 6 * from shu s";
GetDataSet(sql); string sql2 = @"select MAX(shuid)/6 from shu";
conn.Open();
SqlCommand comm = new SqlCommand(sql2,conn);
sum =(int)comm.ExecuteScalar();
if (sum == ) { return; }
this.label2.Text = "总页数" + sum.ToString();
conn.Close();
} //上一页
private void button1_Click(object sender, EventArgs e)
{
if (index == || yeshu == ) { return; } //页数是0则返回
index--;
yeshu--;
this.label1.Text = "第" + yeshu.ToString() + "页";
string sql = @"select top 6 * from shu where shuid not in
(select top (6*" + index + ") shuid from shu)";
GetDataSet(sql); } //下一页
private void button2_Click(object sender, EventArgs e)
{
if (yeshu==sum) //如果翻的页数等于总页数
{
MessageBox.Show("已经是最后一页!");
return;
}
index++;
yeshu++;
this.label1.Text = "第" + yeshu.ToString()+"页";
string sql = @"select top 6 * from shu where shuid not in
(select top (6*"+index+") shuid from shu)";
GetDataSet(sql);
} //绑定
public void GetDataSet(string sql)
{
adapter = new SqlDataAdapter(sql, conn);
if (set.Tables["stu"] != null)
{
set.Tables["stu"].Clear();
}
adapter.Fill(set, "stu"); this.dataGridView1.DataSource = set.Tables["stu"];
}
}
}

Datagridview控件实现分页功能的更多相关文章

  1. DataGridView控件

    DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...

  2. DataGridView控件-[引用]

    DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...

  3. DataGridView控件使用大全说明-各种常用操作与高级操作

    DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...

  4. DataGridView控件使用大全

    转自:http://www.cnblogs.com/xiaofengfeng/archive/2011/04/16/2018504.html DataGridView控件 DataGridView是用 ...

  5. 基于Winform框架DataGridView控件的SqlServer数据库查询展示功能的实现

    关键词:Winform.DataGridView.SqlServer 一个基于winform框架的C/S软件,主要实现对SqlServer数据库数据表的实时查询. 一.为DataGridView添加数 ...

  6. C#实现WinForm DataGridView控件支持叠加数据绑定

    我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...

  7. 在DataGridView控件中加入ComboBox下拉列表框的实现

    在DataGridView控件中加入ComboBox下拉列表框的实现 转自:http://www.cnblogs.com/luqingfei/archive/2007/03/28/691372.htm ...

  8. 实现虚拟模式的动态数据加载Windows窗体DataGridView控件 .net 4.5 (一)

    实现虚拟模式的即时数据加载Windows窗体DataGridView控件 .net 4.5 原文地址 :http://msdn.microsoft.com/en-us/library/ms171624 ...

  9. 如何在winform DataGridView控件的DataGridViewButtonColumn按钮列中禁用按钮

    原文:http://msdn.microsoft.com/en-us/library/ms171619(v=vs.85).ASPX public class DataGridViewDisableBu ...

随机推荐

  1. jQuery EasyUI API 中文文档 - 面板(Panel)

    Panel 面板   用$.fn.panel.defaults重写defaults. 用法示例 创建Panel 1. 经由标记创建Panel 从标记创建Panel更容易.把 'easyui-panel ...

  2. c#局域网聊天软件的实现

    本软件是基于大学寝室局域网聊天的思路.c#源代码如下: using System; using System.Drawing; using System.Collections; using Syst ...

  3. java命令行运行带外部jar

    假设:java 代码路径为com.jdw.test,其中调用了外部jar包 则需要将jar包解压后,放入com同级目录 然后再com目录启动命令行 java com.jdw.test.HelloWor ...

  4. flask twisted 结合方案

    from flask import Flask, render_template, g app = Flask(__name__) @app.route("/") def inde ...

  5. ruby和Python简单对比

    前不久学了ruby,发现ruby和Python非常像,于是自个测试对比了下,测完了才知道网上有现成的……下面是测试结果   序列(包括列表和元组等)有分片的特点:可能会比较方便的提取其中特定元素,暂时 ...

  6. UICollectionView 集合视图用法,自定义Cell

    在View里面 //1.创建UICollectionViewFlowLayout UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFl ...

  7. VB.NET生成Excel,已存在提示框点否时报错

    如题 Exception from HRESULT: 0x800A03EC 最终没有好的解决方案,只好屏蔽掉 Try obook.SaveAs(excelSaveName) Catch ex As S ...

  8. MVC 视频笔记

    1.关闭Jquery的浏览器缓存 $.ajaxSetup({cache:fasle});

  9. 软件看门狗--别让你地程序无响应(使用未公开API函数IsHungAppWindow,知识点较全)

    正文一.概述一些重要的程序,必须让它一直跑着:而且还要时时关心它的状态——不能让它出现死锁现象.当然,如果一个主程序会出现死锁,肯定是设计或者编程上的失误.我们首要做的事是,把这个Bug揪出来.但如果 ...

  10. Dynamics CRM 2013 初体验(3):新增加的功能

    新系统除了修补系统历史漏洞外当然还会添加些比较有意思的新功能,至于这些新功能是否好用那就得看它是否能经过咱们这些使用者的考验了.Dynamics CRM 2013系统将不再支持Dynamics CRM ...