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();
}
查看全文
相关阅读:
第七周上机
第六周作业
第六周上机作业
第五周上机作业
java第四周作业
上机作业
第三次java作业
java作业
第七周作业
JAVA第七周上机作业
原文地址:https://www.cnblogs.com/ahuang1118/p/172571.html
最新文章
[LeetCode每日1题][困难] 460. LFU缓存
[LeetCode每日1题][困难] 42. 接雨水
[LeetCode每日1题][中等] 289. 生命游戏
[LeetCode每日1题][简单] 面试题62. 圆圈中最后剩下的数字
[LeetCode每日1题][中等] 1162. 地图分析
[LeetCode每日1题][简单] 198. 打家劫舍 / 面试题 17.16.按摩师
[LeetCode每日1题][中等] 945. 使数组唯一的最小增量
[LeetCode每日1题][中等] 365. 水壶问题
[笔记]二分查找的几种写法
如果有一天我变得很有钱组——Beta冲刺day1
热门文章
凡事预则立随笔
alpha阶段问题总结随笔
安卓测试
如果有一天我变得很有钱——alpha冲刺测试随笔
如果有一天我变得很有钱——alpha冲刺总结
如果有一天我变得很有钱组——alpha冲刺day10
如果有一天我变得很有钱组——alpha冲刺day9
如果有一天我变得很有钱组——alpha冲刺day8
第八周上机
第七周作业
Copyright © 2011-2022 走看看