| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2112 人关注过本帖, 1 人收藏
标题:C/S中DataGrid数据分页显示
只看楼主 加入收藏
yelang7
Rank: 1
等 级:新手上路
威 望:1
帖 子:265
专家分:0
注 册:2006-11-3
收藏(1)
 问题点数:0 回复次数:13 
C/S中DataGrid数据分页显示
ZD_SSGL_PublicCode PublicCode = new ZD_SSGL_PublicCode();
DataSet myds = new DataSet();
DataSet myds1 = new DataSet();
int pagecount = 3;
int page = 0;
int pagedq = 1;
private void GLQSXX_Load(object sender, EventArgs e)
{
this.dataGrid2.ReadOnly = true;
string sqlselect = "select top 3 * from TBQS";
DataSet ds = new DataSet();
ds = PublicCode.GetMySet(sqlselect);
this.dataGrid2.DataSource = ds.Tables[0].DefaultView;
int count = Convert.ToInt32(PublicCode.GetString("select count(*) from TBQS"));
if (count <= 3)
{
page = 1;
pagecount = count;
}
else if (count % 3 != 0)
{
page = count / 3 + 1;
pagecount = count % 3;
}
else
{
page = count / 3 ;
pagecount = 3;
}
pagesm.Text = "当前为:第1页,共" + page + "页。";
myds = ds;
}
private void bt_goto_Click(object sender, EventArgs e)
{
int count = 0;
DataSet ds = new DataSet();
string sql = "select count(*) from TBQ" ;
try
{
count = Convert.ToInt32(PublicCode.GetString(sql));
}
catch (Exception ex)
{
count=0;
}
int tb_pagedq=0;
if (checkamount(tb_page.Text))
{
tb_pagedq = Convert.ToInt32(tb_page.Text);
}
if (tb_pagedq <= page)
{
string sqlselect = "";
if (tb_pagedq > 1)
{
sqlselect = "select top " + (tb_pagedq - 1) * 3 + " QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS";
try
{
ds = PublicCode.GetMySet(sqlselect);
DataRow dr = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1];
string qsh = dr[0].ToString();
ds.Dispose();
sqlselect = sqlselect = "select top 3 QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS where qs_h>'" + qsh + "' order by QS_H";
ds = PublicCode.GetMySet(sqlselect);
dataGrid2.DataSource = ds.Tables[0].DefaultView;
pagesm.Text = "当前为:第" + tb_pagedq + "页,共" + page + "页。";
}
catch (Exception ex)
{
MessageBox.Show("没有你要的页的数据。");
}
}
else if (tb_pagedq == 1)
{
sqlselect = "select top 3 QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS where order by QS_H";
ds = PublicCode.GetMySet(sqlselect);
dataGrid2.DataSource = ds.Tables[0].DefaultView;
pagesm.Text = "当前为:第1页,共" + page + "页。";
}
else
{
MessageBox.Show("没有你要的页的数据。");
}
}
else
{
MessageBox.Show("没有你要的页的数据。");
}
}
private void NavigateTopPage(object sender, System.EventArgs e)
{
if (dataGrid2.DataSource == null)
{
return;
}
string pageinfo = ((Label)sender).Name;
string sqlselect = "select top 3 QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS";
if (myds.Tables[0].Rows.Count>0)
{
myds1 = myds;
}
DataRow frist, last;
frist = myds1.Tables[0].Rows[0];
string fristqs_h = frist[0].ToString();
last = myds1.Tables[0].Rows[myds1.Tables[0].Rows.Count - 1];
string lastqs_h = last[0].ToString();
string qs_h = "";
if(string.Compare(fristqs_h,lastqs_h)==1)
{
qs_h = fristqs_h;
fristqs_h = lastqs_h;
lastqs_h = qs_h;
}
if (pagecount % 3 != 0)
{
pagecount = pagecount % 3;
}
else
{
pagecount = 3;
}
switch (pageinfo)
{
case "frist":
sqlselect = "select top 3 QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS order by QS_H";
pagesm.Text = "当前为:第1页,共" + page + "页。";
pagedq = 1;
break;
case "last":
sqlselect = "select top "+pagecount+" QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS order by QS_H desc";
pagesm.Text = "当前为:第"+page+"页,共" + page + "页。";
pagedq = page;
break;
case "up":
sqlselect = "select top 3 QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS where qs_h< '" + fristqs_h + "' order by QS_H desc";
if (pagedq == 1)
{
pagesm.Text = "当前为:第1页,共" + page + "页。";
}
else
{
pagesm.Text = "当前为:第" + (--pagedq) + "页,共" + page + "页。";
}
break;
case "down":
sqlselect = "select top 3 QS_H as 寝室号,SS_DM as 宿舍代码,QS_SX as 寝室属性,RZRY_SX as 入住人员属性,"
+ "QSDH as 寝室电话,QSZTBS as 寝室状态标识,CWS as 床位数,BZ as 备注 from TBQS where qs_h>'"+lastqs_h+"' order by QS_H";
if (pagedq == page)
{
pagesm.Text = "当前为:第" + page + "页,共" + page + "页。";
}
else
{
pagesm.Text = "当前为:第" + (++pagedq) + "页,共" + page + "页。";
}
break;
default:
break;
}
myds = PublicCode.GetMySet(sqlselect);
if (myds.Tables[0].Rows.Count > 0)
{
dataGrid2.DataSource = myds.Tables[0];
}
}
相关下载:http://blog.bc-cn.net/user18/101647/archives/2006/2572.shtml
搜索更多相关主题的帖子: DataGrid DataSet 数据 PublicCode int 
2006-11-22 22:44
yelang7
Rank: 1
等 级:新手上路
威 望:1
帖 子:265
专家分:0
注 册:2006-11-3
收藏
得分:0 
都没人顶的哟,这个都是我花了2个小时弄出来的哟.............

想象和行动一致,做最棒的 IT 人. http://yelang7.
2006-11-24 20:03
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
我来支持一下,辛苦了。

飘过~~
2006-11-24 20:34
chenl
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2006-4-29
收藏
得分:0 
顶个,COPY个研究
2006-11-25 13:29
jacklee
Rank: 7Rank: 7Rank: 7
来 自:XAplus
等 级:贵宾
威 望:32
帖 子:1769
专家分:104
注 册:2006-11-3
收藏
得分:0 
苦了,但是发这么长的代码,好吓人哦

XAplus!
讨论群:51090447
删吧删吧,把我的号给删了!
2006-11-25 13:46
漯河
Rank: 4
等 级:贵宾
威 望:12
帖 子:1255
专家分:0
注 册:2006-8-8
收藏
得分:0 
确实吓我一跳


——life is full of ups and downs!
2006-11-25 14:25
frwang
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2006-12-3
收藏
得分:0 
不容易啊

2006-12-03 09:26
YSKING
Rank: 5Rank: 5
来 自:中国绿城
等 级:贵宾
威 望:16
帖 子:1380
专家分:25
注 册:2006-11-11
收藏
得分:0 
还好有下载的

仍然自由自我,永远高唱我歌,走遍千里...
2006-12-03 11:11
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
厉害,我也没见过,楼主厉害。
2006-12-03 12:27
caiyakang
Rank: 2
等 级:新手上路
威 望:5
帖 子:2111
专家分:0
注 册:2005-3-24
收藏
得分:0 
分页效率还算可以!!,但是分页显示重用性太低了,应该把显示的页数和记录分开来写!

中国人的财富网:http://www..cn/
2006-12-03 14:34
快速回复:C/S中DataGrid数据分页显示
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026945 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved