国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

DataList控件也玩分頁(vb)

2024-07-21 02:15:39
字體:
來源:轉載
供稿:網友
今天開發了一個系統。需要用多一行多列去展示圖片。查找了一下datagird的屬性。發現其沒有重復列的功能。于是我使用了datalist的repeatcolumns="4"列重復功能,卻又發現datalist沒有分頁功能。怎么辦?于是寫了下面的關于的分頁程序。發出來希望對正在學asp.net程序的朋友能有所幫作。

下面是全部原代碼,這里我使用了dataadapter與dataset組合,在開始程序的時候,我們首先要熟悉一下asp.net 中 dataadapter,dataset和viewstate的一些屬性和使用方法:http://www.bookd.net/info/1461.htm ;

(本程序在.net framework beta 2下測試通過)

<%@ page language="vb" contenttype="text/html" responseencoding="gb2312" %>
<%@ register tagprefix="head" tagname="menu" src="menu/head.ascx" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<script runat="server">
dim db1 as string = "ietop_article"
dim myconn as new sqlconnection("uid=sa;password=;database=ietop;server=(local)") dim pagesize,pagecount,recordnum,currentpage as integer private sub page_load(byval sender as system.object, byval e as system.eventargs)
每頁顯示的個數 */
pagesize=20
聯接數據庫 */
myconn.open()

計算符合該新聞系統的新聞條數 */
dim strsql as string = "select count(*) as id from ["& db1 &"] where kind_id="&request("id")&""
dim mycomm as sqlcommand = new sqlcommand(strsql,myconn)
dim dr as sqldatareader = mycomm.executereader()
dim intcount as integer
if dr.read() then
intcount =dr("id")
else
intcount = 0
end if
dr.close()
myconn.close()

lblrecordcount.text =intcount
recordnum=intcount
'計算總共有多少頁 */

if recordnum mod pagesize=0 then
pagecount = recordnum/pagesize
else
pagecount = recordnum/pagesize +1
end if
viewstate(pagecount) = pagecount if not ispostback then
currentpage = 0
viewstate("pageindex") = 0
listbind()
end if end sub sub page_onclick(sender as object, e as commandeventargs)
currentpage = viewstate("pageindex")
pagecount = viewstate(pagecount)

dim cmd as string = e.commandname
select case cmd
case "next"
if currentpage<(pagecount-1) then currentpage=+1
case "prev"
if currentpage>0 then currentpage-=1
end select viewstate("pageindex") = currentpage
listbind() end sub
sub listbind()
dim startindex as integer

startindex = currentpage*pagesize
dim strsel as string = "select id,title,dtime,writer,image from ["& db1 &"] where kind_id="&request("id")&" order by id desc"
dim ds as dataset = new dataset()
dim myadapter as sqldataadapter = new sqldataadapter(strsel,myconn)
myadapter.fill(ds,startindex,pagesize,"result")
'讀取分頁數據:使用dataset,dataadapter.fill(objdataset,開始數,結尾數,"數據")
arts_list.datasource = ds.tables("result").defaultview
arts_list.repeatdirection = repeatdirection.horizontal
arts_list.databind() lbnnextpage.enabled = true
lbnprevpage.enabled = true
if(currentpage=(pagecount-1)) then lbnnextpage.enabled = false
if(currentpage=0) then lbnprevpage.enabled = false end sub </script>
<html>
<head>
<title>創藝家裝</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<link href="css/main.css" type="text/css" rel="stylesheet" />
</head>
<body>
<head:menu id="head1" runat="server"/>
<table cellspacing="0" cellpadding="0" width="769" border="0">
<tbody>
<tr>
<td width="158" bgcolor="#f2f2f2">
<img style="width: 158px; height: 50px" height="50" src=http://www.163design.net/a/s/"image/left1.gif" width="165" /></td>
<td width="18" background=http://www.163design.net/a/s/"image/left.gif" rowspan="2" valign="top"><img src=http://www.163design.net/a/s/"image/left.gif" width="18" />
</td>
<td valign="top" width="583" bgcolor="#ffffff" rowspan="2">
<table><tr> <td width="560"><img src=http://www.163design.net/a/s/"images/menu_shang.gif" /></td>
</tr>


|||;
<tr><td height="517" valign="top" >
<table border=0 width=100% cellspacing=0 cellpadding=0 align=center style=font-size:9pt>
<tr>
<td width=50% >
<div align=right>共有展圖
<asp:label id=lblrecordcount runat=server />張</div> </td>

</tr>
</table>
<asp:datalist id="arts_list" runat="server" cellpadding="10" repeatcolumns="4">

<itemtemplate> <a title="<%# container.dataitem("title") %>&#13;&#10; <%# container.dataitem("dtime") %>"
href="news_show1.aspx?kind_id=8&id=<%# container.dataitem("id") %>&class=<%# container.dataitem("title") %>" target="_blank"><img src=<%# container.dataitem("image") %> border="0" width="115" height="80"/> </a>
</itemtemplate>


</asp:datalist>
</td>
</tr>
</table>
<form runat=server >
<table width=100% border=0 align=center style=font-size:9pt>
<tr>

<td align=center>
<asp:linkbutton id=lbnprevpage text=上一頁 commandname=prev oncommand=page_onclick runat=server />
<asp:linkbutton id=lbnnextpage text=下一頁 commandname=next oncommand=page_onclick runat=server />
</td>
</tr>
</table>
</form>
</td>
<td width="10" rowspan="2" align="left" valign="top" background=http://www.163design.net/a/s/"image/right.gif"><img src=http://www.163design.net/a/s/"image/right.gif"></td>
</tr>
<tr>
<td bgcolor="#f2f2f2" height="311">
</td>
</tr>

</table>
<table height="27" cellspacing="0" cellpadding="0" width="769" border="0">
<tbody>
<tr>
<td bgcolor="#dedede">
</td>
</tr>
</tbody>
</table>
</body>
</html>



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 化州市| 漳平市| 汝南县| 项城市| 富锦市| 阳江市| 安塞县| 北碚区| 英吉沙县| 道真| 辽中县| 马公市| 铅山县| 鄄城县| 交城县| 陕西省| 随州市| 河津市| 定南县| 娱乐| 乐东| 海林市| 商水县| 团风县| 定日县| 宝坻区| 镇赉县| 锦州市| 图们市| 沂南县| 鹰潭市| 花莲县| 墨竹工卡县| 丹阳市| 高雄县| 博白县| 青龙| 仁怀市| 乃东县| 玛多县| 盐池县|