扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:冷枫 来源:CSDN 2007年9月24日
关键字:
在本页阅读全文(共2页)
practice_2
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="vb" runat="server">
'定义bindlist子程序,调用pageno(页面位置)参数
sub BindList(PageNo As Integer)
'使用connection对象打开数据连接
Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("db/music.mdb")
'定义sql
Dim strSQL As String = "Select * From 唱片,风格 where 唱片.风格号码 = 风格.风格号码 Order By '添加时间' Desc"
'创建dataadapter对象
Dim objCmd As New OleDbDataAdapter(strSQL, ConnString)
'创建dataset对象
Dim DS As New DataSet()
'调用dataadapter对象的fill()方法讲选取的数据置入dataset对象。
objCmd.Fill(DS, "唱片")
'声明mytable 变量为 datatable对象,并将ds.tables("歌曲")赋值给 mytable变量。
Dim myTable As DataTable = DS.Tables("唱片")
dim pagesize as integer = 2
'显示留言的总条数
dim totalrecord as integer = mytable.rows.count
showtotalrecord.text = totalrecord
'显示流言总页数totalrecord为流言总条数
dim totalpage as integer
if totalrecord < pagesize then
totalpage = 1
else
if totalrecord mod pagesize <> 0 then
totalpage = totalrecord \ pagesize + 1
else
totalpage = totalrecord / pagesize
end if
end if
ShowTotalPage.Text = TotalPage
'创建 tempTable 数据表,其结构与mytable相同,tempTable 数据表
'保存的数据会连接到 Repeater 控件,以显示留言内容。
Dim tempTable As DataTable = myTable.Clone()
Dim I, J As Integer
For I = (PageNo -1) * PageSize To PageNo * PageSize - 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
myRepeater.DataSource = tempTable
myRepeater.DataBind()
End Sub
'此过程用来判断是否应该显示,首页等按钮。
sub showwhatbutton()
if pagelist.selectedindex= 0 then
firstpage.visible = false
prepage.visible = false
else
firstpage.visible = true
prepage.visible = true
end if
if pagelist.selectedindex = pagelist.items.count - 1 then
lastpage.visible = false
nextpage.visible = false
else
lastpage.visible = true
nextpage.visible = true
end if
end sub
'此程序用来创建快速换页菜单
Sub PageListItem()
Dim I As Integer
PageList.Items.Clear()
For I = 0 To ShowTotalPage.Text -1
PageList.Items.Add("第 " & I + 1 & " 页")
Next
End Sub
'页面第一次加载时执行此程序,调用bindlist和pagelistitem子程序并赋值
Sub Page_Init(sender As Object, e As Eventargs)
BindList(1)
PageListItem()
showwhatbutton()
End Sub
'响应下拉菜单 PageList 命令。
Sub PageList_Change(sender As Object, e As EventArgs)
BindList(PageList.SelectedIndex + 1)
showwhatbutton()
End Sub
sub pagechange(sender as object, e as commandeventargs)
select case e.commandargument
case "firstpage"
pagelist.selectedindex = 0
case "nextpage"
pagelist.selectedindex += 1
case "prepage"
pagelist.selectedindex -= 1
case "lastpage"
pagelist.selectedindex = showtotalpage.text - 1
end select
bindlist(PageList.SelectedIndex + 1)
showwhatbutton()
end sub
</script>
<Html>
<Body>
<Form Runat="Server">
收录专辑总数:<Asp:Label Runat="Server" Id="ShowTotalrecord" />
<asp:linkbutton runat="server" ID="firstpage" OnCommand="pagechange" Text="首页" CommandArgument="firstpage"/>
<asp:linkbutton runat="server" ID="lastpage" OnCommand="pagechange" Text="尾页" CommandArgument="lastpage"/>
<asp:linkbutton runat="server" ID="prepage" OnCommand="pagechange" Text="上一页" CommandArgument="prepage"/>
<asp:linkbutton runat="server" ID="nextpage" OnCommand="pagechange" Text="下一页" CommandArgument="nextpage"/>
<br>
总页数:<Asp:Label Runat="Server" Id="showtotalpage" />
目前位于:<asp:dropdownlist runat="Server" ID="PageList" AutoPostBack="True" OnSelectedIndexChanged="PageList_Change" />
<Asp:Repeater Runat="Server" Id="myRepeater">
<ItemTemplate> <Br>
<Br>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="147" rowspan="6"> <div align="center"><Img Src="<%# Container.DataItem("唱片图片") %>"></div></td>
<td width="362"> </td>
</tr>
<tr>
<td>乐队:<%# Container.DataItem("乐队名") %></td>
</tr>
<tr>
<td>唱片:<%# Container.DataItem("唱片名") %></td>
</tr>
<tr>
<td>加入时间:<%# Container.DataItem("添加时间")%> </td>
</tr>
<tr>
<td>推荐指数:<%# Container.DataItem("欣赏指数")%></td>
</tr>
<tr>
<td height="41">唱片风格:<%# Container.DataItem("风格名")%></td>
</tr>
</table>
<Br>
</ItemTemplate>
</Asp:Repeater>
</Form>
</Body>
</Html>
---------------------------------------------------------------
数据库可以按照代码里自行建立
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=373196
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者