zoukankan
html css js c++ java
datalist分页
自己写了个datalist的分页 先暂时放这里 有的地方还要修改 呵呵
static
int
pagecount;
static
int
pagesize
=
9
;
static
int
currentpage;
private
void
GetData()
{
DataTable dt
=
new
DataTable();
SqlConnection con
=
new
SqlConnection(str);
SqlDataAdapter da
=
new
SqlDataAdapter(
"
select * from authors
"
,con);
try
{
da.Fill(dt);
if
(dt
!=
null
&&
dt.Rows.Count
!=
0
)
{
Session[
"
dt
"
]
=
dt;
DataTable newtb
=
new
DataTable();
DataColumn col1
=
new
DataColumn(
"
au_id
"
);
DataColumn col2
=
new
DataColumn(
"
au_lname
"
);
newtb.Columns.Add(col1);
newtb.Columns.Add(col2);
for
(
int
i
=
0
; i
<
pagesize; i
++
)
{
DataRow row
=
newtb.NewRow();
row[
0
]
=
dt.Rows[i][
0
];
row[
1
]
=
dt.Rows[i][
1
];
newtb.Rows.Add(row);
}
DlTest.RepeatColumns
=
3
;
DlTest.DataSource
=
newtb;
DlTest.DataBind();
pagecount
=
dt.Rows.Count
/
pagesize;
if
(pagecount
>
1
)
{
currentpage
=
1
;
LinkLastPage.Visible
=
true
;
LinkNextPage.Visible
=
true
;
}
}
}
catch
{
}
}
private
void
getPageData(
int
cpage)
{
DataTable tb
=
new
DataTable();
tb
=
(DataTable)Session[
"
dt
"
];
DataTable newtb
=
new
DataTable();
DataColumn col1
=
new
DataColumn(
"
au_id
"
);
DataColumn col2
=
new
DataColumn(
"
au_lname
"
);
newtb.Columns.Add(col1);
newtb.Columns.Add(col2);
for
(
int
i
=
(cpage
-
1
)
*
pagesize
+
1
; i
<=
cpage
*
pagesize; i
++
)
{
DataRow row
=
newtb.NewRow();
row[
0
]
=
tb.Rows[i][
0
];
row[
1
]
=
tb.Rows[i][
1
];
newtb.Rows.Add(row);
}
DlTest.RepeatColumns
=
3
;
DlTest.DataSource
=
newtb;
DlTest.DataBind();
}
protected
void
LinkLastPage_Click(
object
sender, EventArgs e)
{
currentpage
-=
1
;
if
(currentpage
<
1
)
{
Response.Write(
"
<script language='javascript'>alert('已是最前一页了!');</script>
"
);
currentpage
=
1
;
return
;
}
getPageData(currentpage);
}
protected
void
LinkNextPage_Click(
object
sender, EventArgs e)
{
currentpage
+=
1
;
if
(currentpage
>
pagecount)
{
Response.Write(
"
<script language='javascript'>alert('已是最后一页了!');</script>
"
);
currentpage
=
pagecount;
return
;
}
getPageData(currentpage);
}
查看全文
相关阅读:
UVa 658 (Dijkstra) It's not a Bug, it's a Feature!
CodeForces Round #288 Div.2
UVa 540 (团体队列) Team Queue
UVa 442 (栈) Matrix Chain Multiplication
CodeForces Round #287 Div.2
CodeForces Round #286 Div.2
CodeForces Round #285 Div.2
UVa 12096 (STL) The SetStack Computer
UVa 101 (模拟) The Blocks Problem
UVa 12171 (离散化 floodfill) Sculpture
原文地址:https://www.cnblogs.com/joy/p/726524.html
最新文章
shell字符串分割截取和转换总结
用node.js写个在Bash上对字符串进行Base64或URL的encode和decode脚本
node.js初步总结
Linux下安装Node.js
Chisel3
Chisel3
Chisel3
Chisel3
Chisel3
Chisel3
热门文章
Chisel3
Chisel3
Chisel3
Chisel3
CodeForces Round #290 Div.2
POJ 1269 (直线相交) Intersecting Lines
POJ 2398 Toy Storage
UVa 1599 (字典序最小的最短路) Ideal Path
POJ 2318 (叉积) TOYS
UVa 1572 (拓扑排序) Self-Assembly
Copyright © 2011-2022 走看看