zoukankan
html css js c++ java
数据的导航与跳转
protected
System.Web.UI.WebControls.DataGrid MyDataGrid;
protected
System.Web.UI.WebControls.Label lblPageCount;
protected
System.Web.UI.WebControls.Label lblCurrentIndex;
protected
System.Web.UI.WebControls.LinkButton btnFirst;
protected
System.Web.UI.WebControls.LinkButton btnPrev;
protected
System.Web.UI.WebControls.LinkButton btnNext;
protected
System.Web.UI.WebControls.LinkButton btnLast;
protected
System.Web.UI.WebControls.TextBox go;
protected
System.Web.UI.WebControls.Label Label1;
private
OleDbConnection cn
=
new
OleDbConnection();
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
btnFirst.Text
=
"
首页
"
;
btnPrev.Text
=
"
前一页
"
;
btnNext.Text
=
"
下一页
"
;
btnLast.Text
=
"
尾页
"
;
OpenDatabase();
BindGrid();
}
private
void
OpenDatabase()
{
cn.ConnectionString
=
"
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
"
+
Server.MapPath(
"
northwind.mdb
"
);
cn.Open();
}
private
void
ShowStats()
{
lblCurrentIndex.Text
=
"
第
"
+
(MyDataGrid.CurrentPageIndex
+
1
).ToString()
+
"
页
"
;
lblPageCount.Text
=
"
总共
"
+
MyDataGrid.PageCount.ToString()
+
"
页
"
;
}
//
btnfirst,btnprev,btnnext,btnlast的事件都要设为PagerButtonClick
public
void
PagerButtonClick(
object
sender, EventArgs e)
{
string
arg
=
((LinkButton)sender).CommandArgument.ToString();
switch
(arg)
{
case
"
next
"
:
if
(MyDataGrid.CurrentPageIndex
<
(MyDataGrid.PageCount
-
1
))
{
MyDataGrid.CurrentPageIndex
+=
1
;
}
break
;
case
"
prev
"
:
if
(MyDataGrid.CurrentPageIndex
>
0
)
{
MyDataGrid.CurrentPageIndex
-=
1
;
}
break
;
case
"
last
"
:
MyDataGrid.CurrentPageIndex
=
(MyDataGrid.PageCount
-
1
);
break
;
default
:
MyDataGrid.CurrentPageIndex
=
System.Convert.ToInt32(arg);
break
;
}
BindGrid();
ShowStats();
}
private
bool
IsNumberic(
string
oText)
{
try
{
int
var1
=
Convert.ToInt32 (oText);
return
true
;
}
catch
{
return
false
;
}
}
public
void
goClick(
object
obj,EventArgs e)
{
if
(go.Text.Trim()
!=
""
&&
this
.IsNumberic(go.Text.Trim()))
{
int
index
=
Int32.Parse(go.Text.Trim())
-
1
;
if
(index
>=
0
&&
index
<
MyDataGrid.PageCount)
{
MyDataGrid.CurrentPageIndex
=
index;
}
BindGrid();
ShowStats();
}
else
{
Response.Write(
"
<script>alert(\'跳转不能为空且必须为数字\')</script>
"
);
}
}
public
void
BindGrid()
{
OleDbConnection myConnection
=
cn;
DataSet ds
=
new
DataSet();
OleDbDataAdapter adapter
=
new
OleDbDataAdapter(
"
Select customerid,orderdate from orders order by orderid desc
"
, myConnection);
adapter.Fill(ds,
"
Document
"
);
MyDataGrid.DataSource
=
ds.Tables[
"
Document
"
].DefaultView;
MyDataGrid.DataBind();
ShowStats();
}
public
void
MyDataGrid_Page(
object
sender, DataGridPageChangedEventArgs e)
{
int
startIndex ;
startIndex
=
MyDataGrid.CurrentPageIndex
*
MyDataGrid.PageSize;
MyDataGrid.CurrentPageIndex
=
e.NewPageIndex;
BindGrid();
ShowStats();
}
查看全文
相关阅读:
火山喷发 计蒜客16862 NOIP模拟赛 概率DP
洛谷 1429 平面最近点对(加强版) 快排 非点分治或kdtree
鬼脚图 计蒜客17353 NOIP模拟 归并排序逆序对
小X的佛光 NOIP模拟赛 倍增LCA 树结构
小X的质数 NOIP模拟赛 魔改线性筛素数
Win7Office2010Flash控件无法使用"此演示文稿中一些控件无法激活,可能这些控件未在此计算机中注册"
【NOILinux】VmWare15使用技巧
【超链接】导航网站
C++统计博客园写过的代码行数
合并多个txt文件到一个
原文地址:https://www.cnblogs.com/ahuang1118/p/172571.html
最新文章
软件工程实践第一次作业--准备
20.11.13 leetcode328
20.11.12 leetcode922
20.11.11 leetcode514
20.11.10 leetcode31
20.11.9 leetcode973
20.11.8 leetcode 1,122
20.11.7 leetcode327 区间和的个数
GPLT L2-018 多项式A除以多项式B 多项式除法
C++ 里面set存储结构体
热门文章
Codeforces 1200D White Lines 二维差分
Codeforces 1114D Flood Fill
Codeforces 1213G Path Queries
Codeforces 1208D Restore Permutation
Codeforces 1197D Yet Another Subarray Problem
货车运输 vijos 1843 NOIP2013 D1T3 最大生成树,并查集,(伪·LCA)
选择客栈 NOIP2011提高组D1T2 单调队列 前缀和
借教室 Vijos 1782 NOIP2012 D2T2 Lazy 线段树
辣鸡(ljh) NOIP模拟赛 模拟 平面几何 数论 化学相关(雾)
信息传递 计蒜客16863 NOIP模拟赛 概率DP
Copyright © 2011-2022 走看看