Datagridview控件实现分页功能
可以进行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控件实现分页功能的更多相关文章
- DataGridView控件
DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...
- DataGridView控件-[引用]
DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...
- DataGridView控件使用大全说明-各种常用操作与高级操作
DataGridView控件 DataGridView是用于Windows Froms 2.0的新网格控件.它可以取代先前版本中DataGrid控件,它易于使用并高度可定制,支持很多我们的用户需要的特 ...
- DataGridView控件使用大全
转自:http://www.cnblogs.com/xiaofengfeng/archive/2011/04/16/2018504.html DataGridView控件 DataGridView是用 ...
- 基于Winform框架DataGridView控件的SqlServer数据库查询展示功能的实现
关键词:Winform.DataGridView.SqlServer 一个基于winform框架的C/S软件,主要实现对SqlServer数据库数据表的实时查询. 一.为DataGridView添加数 ...
- C#实现WinForm DataGridView控件支持叠加数据绑定
我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...
- 在DataGridView控件中加入ComboBox下拉列表框的实现
在DataGridView控件中加入ComboBox下拉列表框的实现 转自:http://www.cnblogs.com/luqingfei/archive/2007/03/28/691372.htm ...
- 实现虚拟模式的动态数据加载Windows窗体DataGridView控件 .net 4.5 (一)
实现虚拟模式的即时数据加载Windows窗体DataGridView控件 .net 4.5 原文地址 :http://msdn.microsoft.com/en-us/library/ms171624 ...
- 如何在winform DataGridView控件的DataGridViewButtonColumn按钮列中禁用按钮
原文:http://msdn.microsoft.com/en-us/library/ms171619(v=vs.85).ASPX public class DataGridViewDisableBu ...
随机推荐
- IE8的项目在IE11下 一些功能无法实现的解决方案
最近改了一些IE11下一些功能无法实现的项目,发现了有一些IE8下的方法 ,在IE11下被取消或者替代了,如下: 1.JavaScript 运行时错误: 对象不支持“attachEvent”属性或方法 ...
- 为什么我们需要性能测试,需要loadrunner
什么是功能: 功能按我理解就是软件实现需求,提供服务,那么功能测试就是实现的需求是否与客户给定需求一致,也就是符合预期结果 什么是性能: 功能是实现需求,提供服务,那么性能就可以理解为服务的好坏.比如 ...
- Eddy's research I
Eddy's research I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Nginx 变量漫谈(七)
在 (一) 中我们提到过,Nginx 变量的值只有一种类型,那就是字符串,但是变量也有可能压根就不存在有意义的值.没有值的变量也有两种特殊的值:一种是“不合法”(invalid),另一种是“没找到”( ...
- 将数组适配到ListView
public class TutListActivity extends ListActivity { @Override public void onCreate(Bundle savedInsta ...
- QT---线程间通信
在 Qt 系统中,运行着一个GUI 主事件线程,这个主线程从窗口系统中获取事件,并将它们分发到各个组件去处理.在 QThread 类中有一种从非主事件线程中将事件提交给一个对象的方法,也就是 QThr ...
- Inno Setup 插件 CallbackCtrl V1.1 (回调函数插件)
原文 http://restools.hanzify.org/article.asp?id=101 VC 重现 InnoCallback 的功能. Version 1.1修正在某些 Windows 平 ...
- Inno Setup:获取isl中的多国语言字串
原文 http://zwkufo.blog.163.com/blog/static/25882512010101041626803/?suggestedreading&wumii 用InnoS ...
- android textView 折叠 展开 ExpandableTextView
项目过程中可能会用到可以折叠和展开的TextView , 这里给出一种实现思路,自定义控件. package com.example.expandtextviewdemo; import androi ...
- Python中:self和__init__的含义 + 为何要有self和__init__
Python中:self和__init__的含义 + 为何要有self和__init__ 背景 回复: 我写的一些Python教程,需要的可以看看 中SongShouJiong的提问: Python中 ...