可以进行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. 第一章——Activity的生命周期

    问题总结: 1.Activity完整的生命周期 2.当打开第二个Activity并关闭时候的生命周期. ①.解释为什么onPause()方法不要有耗时操作 3.Activity发生异常重启的时候问题: ...

  2. HeadFirst设计模式读书笔记--目录

    HeadFirst设计模式读书笔记(1)-策略模式(Strategy Pattern) HeadFirst设计模式读书笔记(2)-观察者模式(Observer Pattern) HeadFirst设计 ...

  3. 在PHP中处理表单之—Checkbox

    原文翻译自:http://www.html-form-guide.com/php-form/php-form-checkbox.html 单个checkbox  形如: <form action ...

  4. phpadmin

    一晚上都在调试数据库,都要疯了,整理如下: 0.Apache服务器的443端口与VMware的冲突,所以要更改配置文件.设为440就可以(这个随意). 1.因为要远程访问,默认密码为空,所以首先给ro ...

  5. swift基本用法-for循环遍历,遍历字典,循环生成数组

    // Playground - noun: a place where people can play import UIKit //--------------------------------- ...

  6. huffman 编码

    huffman压缩是一种压缩算法,其中经典的部分就是根据字符出现的频率建立huffman树,然后根据huffman树的构建结果标示每个字符.huffman编码也称为前缀编码,就是每个字符的表示形式不是 ...

  7. 【最大点独立集】【poj1419】【Graph Coloring】

    题意: 最多能选取多少点,没有边相连. 解法: 取反图,求最大团 代码: #include<cstdio> #include<cstring> #include<iost ...

  8. mysql启动报错:Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

    mysql在首次启动的时候可能会报错:Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist 这时候可以执行脚本 ...

  9. Linux下命令行显示当前全路径方法

    /etc/profile 和 ~/.bashrc 或者直接在用户的.bash_profile中添加 export PS1='[\u@\h \W]\$' 然后执行source命令

  10. UVA 1605 Building for UN

    题意: 有n个国家,要求你设计一栋楼并为这n个国家划分房间,要求国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的 分析: 其实非常简单,完全被样例误导了.只需要设计两层就可以了,每个国家占第 ...