谁能给一段GataList分页程序呢

loveskyline 2003-12-05 03:38:49
最好能提供 .aspx.cs 文件原文

格式:共N页/NS条源码 转第N页 上一页 下一页
...全文
82 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
rock1981 2003-12-05
  • 打赏
  • 举报
回复
CSDN找一下,太多了
网上
sjzwinfor 2003-12-05
  • 打赏
  • 举报
回复
四. 第二种分页浏览数据记录的关键步骤以及实现方法: 其实这二种分页方法在程序设计中是大同小异的,在第二种方法中,其前面的关键步骤中和第一种分页几乎相同,也是要得到浏览数据记录的总数,设定每一页要显示的数据记录个数,计算出总共有多少数据页面等等。这些步骤的实现方法可以参考第一种方法。第二种分页方法和第一种分页方法的主要区别在于数据导航的实现方法上。下列代码功能是实现第二种分页方法数据导航:

Response.Write ( " <p > 数据导航: " )
nPageEnd = nPage + 3
If nPageEnd > nPageCount
nPageEnd = nPageCount
End If
For i = 1 To nPageEnd
If i = nPage Then
Response.Write ( " <b > " & i.ToString ( ) & " </b > " )
Else
Response.Write ( "<A HREF = """ & SCRIPT_NAME & _
"?Page=" & ( i ).ToString ( ) & _
""" > " & i.ToString ( ) & "</A > " )
End If
Next

If nPageEnd < nPageCount Then
Response.Write ( "<A HREF = """ & SCRIPT_NAME & _
"?Page=" & ( nPageEnd + 1 ).ToString ( ) & _
""" >更多...</A > " )
End If


五. 第二种分页浏览数据记录的完整源程序代码(no2.aspx):

no2.aspx和no1.aspx在程序设计的思想和方法上大致相同,下面是no2.aspx的源程序,具体如下:

<% @ Page Language = "VB" %>
<% @ Import Namespace = "System.Data" %>
<% @ Import Namespace = "System.Data.OleDb" %>

<script runat = "server" >
Const Record_Per_Page As Short = 5 '定义每一页显示的记录数
Private Script_Name As String

Sub Page_Load ( Source As Object , e As EventArgs )
Script_Name = GetPageName ( )
'第二种方式来分页显示数据
ShowRecords ( )
End Sub

'得到起始浏览超链接字符串
Function GetPageName ( ) As String
Dim Str As String
Dim Pos As Short
Str = Request.ServerVariables ( "Script_Name" ).Trim ( )
Pos = Str.LastIndexOf ( "/" )
If Pos >= 0 Then
Return Str.SubString ( Pos + 1 )
Else
Return Str
End If
End Function

Private Sub ShowRecords ( )
Dim strConn As String '定义数据连接字符串
Dim SQL As String '定义SQL语句
Dim odConn As OleDbConnection
Dim odAdapt As OleDbDataAdapter
Dim DS As DataSet '创建DataSet对象
Dim DT As DataTable '创建DataTable对象
Dim nRecCount As Integer '保存记录总数
Dim nPageCount As Integer '保存总共的数据页面数目
Dim nPage As Integer '存放要浏览当前数据页面号
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim nPageEnd As Integer '存储当前页面的最后一面的序号
Dim i As Integer
'确认要浏览的页面序号
nPage = Convert.ToInt32 ( Request.QueryString ( "Page" ) )
SQL = "SELECT * FROM tblItem "

'创建数据连接字符串
strConn = " Provider = Microsoft.Jet.OLEDB.4.0 ; " & _
" Data Source = " & Server.MapPath ( "data.mdb" ) & " ; " & _
" User ID = ; Password = ; "
Try
'得到数据记录总数
odConn = New OleDbConnection ( strConn )
odAdapt = New OleDbDataAdapter ( SQL , odConn )
DS = New DataSet
odAdapt.Fill ( DS )
DT = DS.Tables ( 0 )
nRecCount = DT.Rows.Count
Catch e As Exception
Response.Write("错误信息: <b >" & e.Message & "</b > <p > " )
nRecCount = 0
End Try

If nRecCount > 0 Then
' 确定数据记录要显示的页面数
nPageCount = nRecCount \ Record_Per_Page
If nRecCount Mod Record_Per_Page > 0 Then
nPageCount += 1
End If

'确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
If nPage < 1 Then
nPage = 1
End If
If nPage > nPageCount Then
nPage = nPageCount
End If

Response.Write ( "总共有数据记录" & nRecCount.ToString ( ) & " 条" & "。<br >" )
Response.Write(" <p > <b >第二种分页显示为:</b > <p > " )

'确认当前页面的开始记录和终止记录
nStart = Record_Per_Page * ( nPage - 1 )
nEnd = nStart + Record_Per_Page - 1
If nEnd > nRecCount - 1 Then
nEnd = nRecCount - 1
End If
'在屏幕中输出记录
For i = nStart To nEnd
Response.Write ( DT.Rows ( i ) ( "ItemName" ) & " <br > " )
Next
End If
Response.Write ( " <p > 数据导航: " )
nPageEnd = nPage + 3
If nPageEnd > nPageCount
nPageEnd = nPageCount
End If
For i = 1 To nPageEnd
If i = nPage Then
Response.Write ( " <b > " & i.ToString ( ) & " </b > " )
Else
Response.Write ( "<A HREF = """ & SCRIPT_NAME & _
"?Page=" & ( i ).ToString ( ) & _
""" > " & i.ToString ( ) & "</A > " )
End If
Next

If nPageEnd < nPageCount Then
Response.Write ( "<A HREF = """ & SCRIPT_NAME & _
"?Page=" & ( nPageEnd + 1 ).ToString ( ) & _
""" >更多...</A > " )
End If
End Sub
</script >


本文介绍的这二种分页浏览记录类型虽然采用的数据库都是本地数据库,但对其他类型的数据库也是一样适用的,这只需要修改一下数据连接字符串就可以实现了,譬如如果采用了SQL Server数据库。此SQL Server数据库服务器是"Server1",数据库是"Data",用户名为缺省的"sa",没有设定密码。只需要把上面二段程序中的字符串"strConn"变换成:

strConn = "Provider = SQLOLEDB.1 ; Persist Security Info = False ; User ID = sa ; Initial Catalog = Data ; Data Source = server1 "


就可以实现了。

六. 总结:

本文介绍的二种分页浏览数据记录方法在ASP.NET数据库编程方面是非常有用的,因为在数据处理方面,分页显示记录比起其他的一些处理,譬如:数据修改、删除等都要难些。希望上面的这些内容对你利用ASP.NET开发数据库程序有所帮助。
sjzwinfor 2003-12-05
  • 打赏
  • 举报
回复
(4).数据导航的实现方法:

其实数据导航是通过对参数"Page"赋值来实现的,其中程序中的"nPage"是当前数据页面序号, "nPageCount"是数据页面的总和。下面是实现这些数据导航的具体实现代码:

Response.Write ( " <p >数据导航:<A HREF = """ & Script_Name & _
"?Page=" & ( 1 ).ToString ( ) & _
""">首 页 </A >" )
Response.Write( "      " )
'浏览"上一页"处理办法
Response.Write ( " <A HREF = """ & Script_Name & _
"?Page=" & ( nPage - 1 ).ToString ( ) & _
""" >上一页</A > " )
Response.Write ( "     " )
'浏览"下一页"处理办法
Response.Write ( "<A HREF =""" & Script_Name & _
"?Page=" & ( nPage + 1 ).ToString ( ) & _
""" >下一页</A > " )
Response.Write ( "    " )
'浏览"尾页"处理办法
Response.Write ( "<A HREF = """ & Script_Name & _
"?Page=" & ( nPageCount ).ToString ( ) & _
""" >尾 页</A > " )
'显示当前页和合计页数
Response.Write ( "    " & "页次:"& nPage.ToString ( ) & "/" & nPageCount.ToString ( ) & " <br > " )


(5).显示不同页面的数据记录:

根据超链接字符串得到"Page"值,然后根据此值来得到在此页面中要显示的起始记录号和结束记录号,再通过一个循环把这些记录给显示出来。下面这行代码是读取参数"Page":

nPage = Convert.ToInt32 ( Request.QueryString ( "Page" ) )


下面这些代码是根据用户想要去的页面得到起始记录号和结尾记录号,并通过屏幕显示出来:

Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim i As Integer
nStart = Record_Per_Page * ( nPage - 1 )
nEnd = nStart + Record_Per_Page - 1
If nEnd > nRecCount - 1 Then
nEnd = nRecCount - 1
End If
'在屏幕中输出记录
For i = nStart To nEnd
Response.Write ( DT.Rows ( i ) ( "ItemName" ) & " <br > " )
Next

在本文介绍的二种分页浏览记录类型中,对于数据显示,我们采用了简化处理。我们知道在浏览器上,浏览记录一般都是通过DbGrid的形式来实现的,这一点在其实也好实现,读者只需稍微修改一下本文中的程序代码就可以实现。

三. 第一种分页浏览数据记录的完整程序代码(no1.aspx):

组织一下上面的这些步骤的实现方法,可以得到下列完整代码:

<% @ Page Language = "VB" %>
<% @ Import Namespace = "System.Data" %>
<% @ Import Namespace = "System.Data.OleDb" %>
<script runat = "server" >
Const Record_Per_Page As Short = 5 '定义每一页显示的记录数
Private Script_Name As String

Sub Page_Load ( Source As Object , e As EventArgs )
Script_Name = GetPageName ( )
'第一种方式来分页显示数据
ShowRecords ( )
End Sub
'得到起始浏览超链接字符串
Function GetPageName ( ) As String
Dim Str As String
Dim Pos As Short
Str = Request.ServerVariables ( "Script_Name" ).Trim ( )
Pos = Str.LastIndexOf ( "/" )
If Pos >= 0 Then
Return Str.SubString ( Pos + 1 )
Else
Return Str
End If
End Function

'此函数的功能是分页显示数据库中的记录
Private Sub ShowRecords ( )
Dim strConn As String '定义数据连接字符串
Dim SQL As String '定义SQL语句
Dim odConn As OleDbConnection
Dim odAdapt As OleDbDataAdapter
Dim DS As DataSet '创建DataSet对象
Dim DT As DataTable '创建DataTable对象
Dim nRecCount As Integer '保存记录总数
Dim nPageCount As Integer '保存总共的数据页面数目
Dim nPage As Integer '存放要浏览当前数据页面号
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim i As Integer

'确认要浏览的页面序号
nPage = Convert.ToInt32 ( Request.QueryString ( "Page" ) )
SQL = "SELECT * FROM tblItem "

'创建数据连接字符串
strConn = " Provider = Microsoft.Jet.OLEDB.4.0 ; " & _
" Data Source = " & Server.MapPath ( "data.mdb" ) & " ; " & _
" User ID = ; Password = ; "
Try
'得到数据记录总数
odConn = New OleDbConnection ( strConn )
odAdapt = New OleDbDataAdapter ( SQL , odConn )
DS = New DataSet
odAdapt.Fill ( DS )
DT = DS.Tables ( 0 )
nRecCount = DT.Rows.Count
Catch e As Exception
Response.Write("错误信息: <b>" & e.Message & "</b><p>")
nRecCount = 0
End Try

'判断是否存在数据记录
If nRecCount > 0 Then
' 确定数据记录要显示的页面数
nPageCount = nRecCount \ Record_Per_Page
If nRecCount Mod Record_Per_Page > 0 Then
nPageCount += 1
End If

'确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
If nPage < 1 Then
nPage = 1
End If
If nPage > nPageCount Then
nPage = nPageCount
End If

Response.Write ( "总共有数据记录" & nRecCount.ToString ( ) & " 条" & "。<br >" )
Response.Write(" <p > <b >第一种分页显示为:</b > <p > " )

'确认当前页面的开始记录和终止记录
nStart = Record_Per_Page * ( nPage - 1 )
nEnd = nStart + Record_Per_Page - 1
If nEnd > nRecCount - 1 Then
nEnd = nRecCount - 1
End If
'在屏幕中输出记录
For i = nStart To nEnd
Response.Write ( DT.Rows ( i ) ( "ItemName" ) & " <br > " )
Next
End If
'浏览"首页"处理办法
Response.Write ( " <p >数据导航:<A HREF = """ & Script_Name & _
"?Page=" & ( 1 ).ToString ( ) & _
""">首 页 </A >" )
Response.Write( "      " )
'浏览"上一页"处理办法
Response.Write ( " <A HREF = """ & Script_Name & _
"?Page=" & ( nPage - 1 ).ToString ( ) & _
""" >上一页</A > " )
Response.Write ( "     " )
'浏览"下一页"处理办法
Response.Write ( "<A HREF =""" & Script_Name & _
"?Page=" & ( nPage + 1 ).ToString ( ) & _
""" >下一页</A > " )
Response.Write ( "    " )
'浏览"尾页"处理办法
Response.Write ( "<A HREF = """ & Script_Name & _
"?Page=" & ( nPageCount ).ToString ( ) & _
""" >尾 页</A > " )
'显示当前页和合计页数
Response.Write ( "    " & "页次:"& nPage.ToString ( ) & "/" & nPageCount.ToString ( ) & " <br > " )
End Sub
</script >
sjzwinfor 2003-12-05
  • 打赏
  • 举报
回复
一. 本文程序设计和运行的软件环境:

(1).微软公司视窗2000服务器版

(2)..Net FrameWork SDK Beta 2

二. 第一种分页浏览数据记录的关键步骤以及实现方法:

(1).首先要得到初始浏览数据记录的超链接字符串:

这其实很关键,因为在第一种分页浏览中的"首页"、"下一页"等操作,都是通过在这个超链接字符串后面加入要浏览页面的参数来实现的,在本文的程序中是通过GetPageName ( )函数来实现的。此函数具体如下:

Function GetPageName ( ) As String
Dim Str As String
Dim Pos As Short
Str = Request.ServerVariables ( "Script_Name" ).Trim ( )
Pos = Str.LastIndexOf ( "/" )
If Pos >= 0 Then
Return Str.SubString ( Pos + 1 )
Else
Return Str
End If
End Function


(2).要得到你所要浏览的数据记录总数:

在本文中,为了方便,我们是把数据表"tblItem"中的全部记录都拿来浏览。ASP.NET页面通过ADO.NET来得到数据表"tblItem"。下面代码就是利用ADO.NET来得到"tblItm"表中记录总数的程序代码:

<% @ Page Language = "VB" %>
<% @ Import Namespace = "System.Data" %>
<% @ Import Namespace = "System.Data.OleDb" %>
<script runat = "server" >
Dim strConn As String '定义数据连接字符串
Dim SQL As String '定义SQL语句
Dim odConn As OleDbConnection
Dim odAdapt As OleDbDataAdapter
Dim DS As DataSet '创建DataSet对象
Dim DT As DataTable '创建DataTable对象
Dim nStart As Integer '存放当前页面的起始记录序号
Dim nEnd As Integer '存放当前页面的终止记录序号
Dim i As Integer

'确认要浏览的页面序号
nPage = Convert.ToInt32 ( Request.QueryString ( "Page" ) )
SQL = "SELECT * FROM tblItem "

'创建数据连接字符串
strConn = " Provider = Microsoft.Jet.OLEDB.4.0 ; " & _
" Data Source = " & Server.MapPath ( "data.mdb" ) & " ; " & _
" User ID = ; Password = ; "
Try
'得到数据记录总数
odConn = New OleDbConnection ( strConn )
odAdapt = New OleDbDataAdapter ( SQL , odConn )
DS = New DataSet
odAdapt.Fill ( DS )
DT = DS.Tables ( 0 )
'得到数据记录总数
nRecCount = DT.Rows.Count
Catch e As Exception
Response.Write("错误信息: <b>" & e.Message & "</b><p>")
nRecCount = 0
End Try
</script >


(3).计算出浏览的数据记录总共页面数:

在浏览页面中,我们发现了每一页只浏览5条记录,你可以通过修改程序中定义一个常量"Record_Per_Page"来改变每一页浏览数据记录的个数。在知道了要浏览数据记录的总数后,通过下面代码来计算出要显示这些数据记录所需要的页面总数:

Const Record_Per_Page As Short = 5 '定义每一页显示的记录数
Dim nPageCount As Integer '保存总共的数据页面数目
Dim nPage As Integer '存放要浏览当前数据页面号
nPageCount = nRecCount \ Record_Per_Page
If nRecCount Mod Record_Per_Page > 0 Then
nPageCount += 1
End If
'确认浏览命令中的页面参数是否越界,如果越界则重置页面序号
If nPage < 1 Then
nPage = 1
End If
If nPage > nPageCount Then
nPage = nPageCount
End If
liuvb 2003-12-05
  • 打赏
  • 举报
回复
孟子e章的网站多的是,看一下吧
http://xml.sz.luohuedu.net/xml/ShowList.asp?id=1
xiaomaolover 2003-12-05
  • 打赏
  • 举报
回复
Sub DropDownList2_SelectedIndexChanged(sender As Object, e As EventArgs)

DropDownList1.SelectedIndex=0
BindList(DropDownList1.SelectedIndex+1)
PageListItem()
ShowWhatButton()
End Sub


'''''''show linkbutton ( next or previous )'''''''''''''''''''''''''''''''''''''''''''''''''''
Sub LinkButton1_Click(sender As Object, e As EventArgs)
DropDownList1.SelectedIndex=0
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()
End Sub

Sub LinkButton2_Click_1(sender As Object, e As EventArgs)


DropDownList1.SelectedIndex=DropDownList1.SelectedIndex+1
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()

End Sub

Sub LinkButton3_Click_1(sender As Object, e As EventArgs)

DropDownList1.SelectedIndex=DropDownList1.SelectedIndex-1
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()
End Sub

Sub LinkButton4_Click_1(sender As Object, e As EventArgs)
DropDownList1.SelectedIndex=Label2.text-1
Bindlist(DropDownList1.SelectedIndex+1)
ShowWhatButton()
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Sub ShowWhatButton()
IF DropDownList1.SelectedIndex=0 THEN

LinkButton3.Enabled=False

ELSE

LinkButton3.Enabled=True

END IF


IF DropDownList1.SelectedIndex=Label2.text-1 THEN

LinkButton2.Enabled=False

ELSE

LinkButton2.Enabled=True

END IF

End Sub

</script>
<html>
<head>
<!-- #include File="SqlFunction.inc" -->
</head>
<body>
<form runat="server">
<p>
</p>
<table width="760" border="1">
<tbody>
<tr>
<td height="220">
<table height="220" width="200" border="1">
<tbody>
<tr>
<td height="208">
<asp:DataList id="DataList1" runat="server" Width="101px" Height="101px" BackColor="White" BorderStyle="Double" GridLines="Horizontal" BorderWidth="3px" BorderColor="#336666" CellPadding="4">
<ItemStyle forecolor="#333333" backcolor="White"></ItemStyle>
<FooterStyle forecolor="#333333" backcolor="White"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#336666"></HeaderStyle>
<SelectedItemStyle font-bold="True" forecolor="White" backcolor="#339966"></SelectedItemStyle>
<ItemTemplate>
<table width="300">
<tbody>
<tr>
<td>
<%# container.dataitem("XingMing")%>
</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table width="750" border="1">
<tbody>
<tr>
<td width="630">
<div style="FONT-SIZE: smaller" align="left">TotalRecorD: <asp:Label id="Label1" runat="server">Label</asp:Label> || TotalPage: <asp:Label id="Label2" runat="server">Label</asp:Label> ||
C<a target="FrameBody">urrentPage</a>:
<asp:DropDownList id="DropDownList1" runat="server" BackColor="PaleGreen" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Font-Size="Smaller"></asp:DropDownList>
 || PerPageRecord:
<asp:DropDownList id="DropDownList2" runat="server" BackColor="PaleGreen" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" Font-Size="Smaller">
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="50">50</asp:ListItem>
</asp:DropDownList>
</div>
</td>
</tr>
<tr>
<td>
<div style="FONT-SIZE: smaller" align="left">
</div>
<div align="left">
</div>
<div align="left">
</div>
<div align="left">
</div>
<div align="left">
</div>
<div align="left">
</div>
<div align="right">
<asp:LinkButton id="LinkButton1" onclick="LinkButton1_Click" runat="server" Font-Size="Smaller">Frist</asp:LinkButton>
  <asp:LinkButton id="LinkButton2" onclick="LinkButton2_Click_1" runat="server" Font-Size="Smaller">Next</asp:LinkButton>
 
<asp:LinkButton id="LinkButton3" onclick="LinkButton3_Click_1" runat="server" Font-Size="Smaller">Previous</asp:LinkButton>
 
<asp:LinkButton id="LinkButton4" onclick="LinkButton4_Click_1" runat="server" Font-Size="Smaller">Last</asp:LinkButton>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<div align="right">
</div>
</form>
</body>
</html>
xiaomaolover 2003-12-05
  • 打赏
  • 举报
回复
<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
'
'''''''''''''''''''''''datalist pagination code''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub BindList(PageNo as Integer)

Dim MyTable As DataTable=CreateDataSet("select * from YongHu", "mm", "YongHu").tables("YongHu")
Dim TotalRecord=MyTable.rows.count
Label1.text=TotalRecord

dim TotalPage as Integer

IF TotalRecord < DropDownList2.SelectedItem.Value THEN

TotalPage=1

ELSE

IF TotalRecord Mod DropDownList2.SelectedItem.Value <>0 THEN

TotalPage =TotalRecord\DropDownList2.SelectedItem.Value+1

ELSE

TotalPage =TotalRecord/DropDownList2.SelectedItem.Value

END IF

END IF
label2.text= TotalPage


Dim TempTable as DataTable=MyTable.Clone()

Dim i ,j as integer


For I=(PageNo-1) * DropDownList2.SelectedItem.Value to PageNo*DropDownList2.SelectedItem.Value-1

If I> myTable.Rows.Count-1 Then Exit for

Dim newRow as DataRow=TempTable.NewRow()

For J=0 TO MyTable.Columns.Count-1

newRow(MyTable.Columns(j).ColumnName)=MyTable.Rows(I).Item(j)

Next

TempTable.Rows.Add(NewRow)

Next

DataList1.datasource=TempTable
DataList1.databind()

End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



''''''''page the frist load''''''''''''''''''''''''''''''''''''''''''''''''
Sub Page_Init(sender As Object, e As EventArgs)

BindList(1)
PageListItem()
ShowWhatButton()

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''insert DropDownlist pageRecord'''''''''''''''''''''''''
Sub PageListItem()
Dim I as Integer
DropDownList1.Items.Clear()
For I=0 To label2.text-1
DropDownList1.Items.add(i+1)
next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



'''''''''''''''''change PageRecord'''''''''''''''''''''
Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
Bindlist(DropDownList1.SelectedIndex+1)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
webdiyer 2003-12-05
  • 打赏
  • 举报
回复
用这个控件很简单:http://www.webdiyer.com
menuvb 2003-12-05
  • 打赏
  • 举报
回复
强烈火推荐初学者 下载这个参考,
http://aspxcn.com/dotnetdown/default.aspx?classid=1&subclass=13
互动留言簿.NET2.0最终版(全源码提供)
jhonsn 2003-12-05
  • 打赏
  • 举报
回复
http://xml.sz.luohuedu.net/xml/Search.asp?keyWord=datalist
monkeys 2003-12-05
  • 打赏
  • 举报
回复
给我邮箱,我发给你
li8301 2003-12-05
  • 打赏
  • 举报
回复
<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<Script Language="C#" Runat="Server">
/*
Create By 飞刀
http://www.aspcn.com
2001-7-25 01:44

Support .Net Framework Beta 2
*/
OleDbConnection MyConn;
int PageSize,RecordCount,PageCount,CurrentPage;
public void Page_Load(Object src,EventArgs e)
{
//设定PageSize
PageSize = 10;

//连接语句
string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"..\\DataBase\\db1.mdb;";
MyConn = new OleDbConnection(MyConnString);
MyConn.Open();

//第一次请求执行
if(!Page.IsPostBack)
{
ListBind();
CurrentPage = 0;
ViewState["PageIndex"] = 0;

//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString();

//计算总共有多少页
PageCount = RecordCount/PageSize;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
}
//计算总共有多少条记录
public int CalculateRecord()
{
int intCount;
string strCount = "select count(*) as co from Score";
OleDbCommand MyComm = new OleDbCommand(strCount,MyConn);
OleDbDataReader dr = MyComm.ExecuteReader();
if(dr.Read())
{
intCount = Int32.Parse(dr["co"].ToString());
}
else
{
intCount = 0;
}
dr.Close();
return intCount;
}

ICollection CreateSource()
{

int StartIndex;

//设定导入的起终地址
StartIndex = CurrentPage*PageSize;
string strSel = "select * from Score";
DataSet ds = new DataSet();

OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,StartIndex,PageSize,"Score");

return ds.Tables["Score"].DefaultView;
}
public void ListBind()
{
score.DataSource = CreateSource();
score.DataBind();

lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false;
if(CurrentPage==0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage+1).ToString();

}

public void Page_OnClick(Object sender,CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"];

string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch(cmd)
{
case "next":
if(CurrentPage<(PageCount-1)) CurrentPage++;
break;
case "prev":
if(CurrentPage>0) CurrentPage--;
break;
}

ViewState["PageIndex"] = CurrentPage;

ListBind();

}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录
当前为<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页

<asp:DataList id="score" runat="server"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="Gainsboro"
EditItemStyle-BackColor="yellow"
>
<ItemTemplate>
姓名:<%# DataBinder.Eval(Container.DataItem,"Name") %>
<asp:LinkButton id="btnSelect" Text="编辑" CommandName="edit" runat="server" />
</ItemTemplate>
</asp:DataList>
<asp:LinkButton id="lbnPrevPage" Text="上一页" CommandName="prev" OnCommand="Page_OnClick" runat="server" />
<asp:LinkButton id="lbnNextPage" Text="下一页" CommandName="next" OnCommand="Page_OnClick" runat="server" />

</form>
</body>
</html>
sjc0 2003-12-05
  • 打赏
  • 举报
回复
转贴
<%@ Import NameSpace="System.Data.OleDb" %>
<%@ Import NameSpace="System.Data" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack() Then
intPageSize.Text = "2"
intCurrIndex.Text = "0"
DataBind()
End If
End Sub

Private Sub DataBind()
Dim CnString As String
CnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
CnString = CnString + Server.MapPath("dataDB.mdb"))
Dim objConn As New OleDbConnection(CnString)
Dim objDA As New OleDbDataAdapter("SELECT * FROM Document ORDER BY CreateDate DESC", objConn)
Dim objDS As New DataSet()

If Not Page.IsPostBack() Then
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
End If

objDA.Fill (objDS, CInt(intCurrIndex.Text), CInt(intPageSize.Text), "Document")

dList.DataSource = objDS.Tables(0).DefaultView
dList.DataBind()
objConn.Close()
PrintStatus()
End Sub

Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub


Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub

Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub

Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt as Integer

tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub

Private Sub PrintStatus()
lblStatus.Text = "总记录数:<b>" & intRecordCount.Text
lblStatus.Text += "</b> 当前:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) / CInt(intPageSize.Text)+1))
lblStatus.Text += "</b>/<b>"

If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) / CInt(intPageSize.Text)+1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<TABLE height="528" cellSpacing="0" cellPadding="0" width="244" border="0"
ms_2d_layout="TRUE">
<TBODY>
<TR vAlign="top">
<TD width="244" height="528">
<form id="Form1" method="post" runat="server">
<TABLE height="227" cellSpacing="0" cellPadding="0" width="516" border="0"
ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="10" height="15"></TD>
<TD width="506"></TD>
</TR>
<TR vAlign="top">
<TD height="48"></TD>
<TD>
<h2 align="center"><font face="verdana">Paging in DataList</font></h2>
</TD>
</TR>
<TR vAlign="top">
<TD height="106"></TD>
<TD>
<a name="this"></a>
</TD>
</TR>
<TR vAlign="top">
<TD height="19"></TD>
<TD rowSpan="2">
<table width="505" align="right" height="25">
<tr>
<td width="76%" align="left">
<asp:label ID="lblStatus" Runat="server" Font-Name="verdana" Font-Size="10pt" />
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefFirst" onserverclick="ShowFirst" runat="server">
<b><<</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefPrevious"
onserverclick="ShowPrevious" runat="server">
<b><</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefNext" onserverclick="ShowNext" runat="server">
<b>></b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefLast" onserverclick="ShowLast" runat="server">
<b>>></b></a>
</td>
</tr>
</table>
</TD>
</TR>
<TR vAlign="top">
<TD height="19"></TD>
<TD>
<asp:label ID="intPageSize" Visible="False" Runat="server" /></TD>
</TR>
<TR vAlign="top">
<TD height="20"></TD>
<TD>
<asp:label ID="intRecordCount" Visible="False" Runat="server" /></TD>
</TR>
<asp:DataList ID="dList" Runat="server" Width="100%"
ItemStyle-BackColor="Beige" ItemStyle-Font-Name="宋体"
BorderWidth="1" HeaderStyle-Font-Name="Verdana" EnableViewState="False">
<HeaderTemplate>
<table width="100%" style="font: 10pt verdana" cellpadding="0" cellspacing="0">
<tr style="background-color:FF0000">
<th align="left">
<font color="#FFFFFF">Store ID</font></th>
<th align="left">
<font color="#FFFFFF">Order Number</font></th>
<th align="left">
<font color="#FFFFFF">Order Date</font></th>
<th align="left">
<font color="#FFFFFF">Qty</font></th>
<th align="left">
<font color="#FFFFFF">Title ID</font></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#f5f5dc">
<td><%# DataBinder.Eval(Container.DataItem, "id") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "Title") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "Author") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "Source") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "CreateDate") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</TABLE>
</FooterTemplate>
</asp:DataList>
<asp:label ID="intCurrIndex" Visible="False" Runat="server" />
</TABLE>
</FORM>
</TD></TR>
</TBODY>
</TABLE>
</body>
</HTML>
hiyo 2003-12-05
  • 打赏
  • 举报
回复
网上源码有的是,搜一把试试.
最后顺便帮你顶一下

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧