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();
}
查看全文
相关阅读:
CentOS7安装Dnsmasq并更新最新版
VMware vCenter Server Appliance(VCSA )6.7 部署,许可证破解
vsphere6.7虚拟机与ESXI时间同步
oracle使用存储过程返回数据集
如何让CheckBoxList横着显示
在oracle中创建自动增长字段
oracle 11g安装客户端后使用ps/sql连接提示TNS适配器错误的解决办法
myeclipse 网站项目部署失败
Opera Dragonfly本地化
ExtJs的fireEvent事件
原文地址:https://www.cnblogs.com/ahuang1118/p/172571.html
最新文章
sql查看表的锁并解锁
修己,以清心为要。涉世,以慎言为先。
多線程訪問控件
集合属性的持久化用集合编辑器编辑集合属性并自动生成代码
C#中动态加载和卸载DLL
fastjson 1.2.47 payload分析
fastjson 1.2.68利用
fastjson 1.2.68 payload分析
数字区块链技术:身份和访问管理
APMServ 5.2.6.Apache启动失败,请检查相关配置。2.MySQL5.1启动失败的解决方法
热门文章
004.添加pch文件_项目配置
012.Bug(精度丢失)_02
013.消息_环信01
008.屏幕尺寸_代码布局
009.学习资源和计划管理
005.block_基础语法
006.宏_代码效率
011.Bug(duplicate symbol)_01
007.OC基础
010.优秀博客
Copyright © 2011-2022 走看看