后台代码: Imports System.Data Imports System.Data.oledb Imports System.Web.UI.WebControlsPublic Class maillist Inherits System.Web.UI.Page #Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList Protected WithEvents pagetotal1, pageno, total, label1, label2, label3 As System.Web.UI.WebControls.Label Protected WithEvents first, up, down, last, hyperlink1, hyperlink2, hyperlink3, hyperlink4 As System.web.ui.webcontrols.HyperLink '注意: 以下占位符声明是 Web 窗体设计器所必需的。 '不要删除或移动它。 Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load binding() hit() '在此处放置初始化页的用户代码 End Sub Sub binding() Dim con1 As New conclass.conclass con1.con1.Open() Dim sql As String sql = "select id, name,title,hfdateendtime,hits from xx where hf = True order by hfdateendtime" Dim adapter1 As New OleDbDataAdapter(sql, con1.con1) Dim dataset11 As New DataSet adapter1.Fill(dataset11, "xx") Dim pads As New PagedDataSource pads.DataSource = dataset11.Tables("xx").DefaultView pads.AllowPaging = True pads.PageSize = 15 pagetotal1.Text = pads.PageCount.ToString() label2.Text = pads.PageCount.ToString Dim currentpage As Integer If Not Request.QueryString("page") Is Nothing Then currentpage = Convert.ToInt32(Request.QueryString("page")) Else currentpage = 1 End If pads.CurrentPageIndex = currentpage - 1 label1.Text = currentpage.ToString pageno.Text = currentpage.ToString If Not pads.IsFirstPage Then up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(currentpage - 1) hyperlink2.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentpage - 1) first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1" End If If Not pads.IsLastPage Then down.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentpage + 1) hyperlink3.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentpage + 1) last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(pads.PageCount) End If If pads.IsFirstPage Then first.NavigateUrl = "" hyperlink1.NavigateUrl = "" End If If pads.IsLastPage Then last.NavigateUrl = "" hyperlink3.NavigateUrl = "" End If DataList1.DataSource = pads DataList1.DataBind() End Sub Sub hit() Dim i As Integer i = Request.QueryString("id") Dim sql As String Dim conn As New conclass.conclass conn.con1.Open() sql = "update xx set hits = hits+1 where id=" & i Dim cmdoledb As New OleDbCommand(sql, conn.con1) cmdoledb.ExecuteNonQuery() conn.con1.Close() End Sub Private Sub DataList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged End Sub End Class
cs文件加
protected System.Web.UI.WebControls.XXXXXX XXXXXX;
<%@ Page Language="vb" ResponseEncoding="gb2312" CodeBehind="maillist.aspx.vb" AutoEventWireup="false" Inherits="xinxiang.maillist" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>maillist</title>
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="VisualStudio.HTML" name="ProgId">
<meta content="Microsoft Visual Studio .NET 7.1" name="Originator">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">BODY { FONT-SIZE: 12px }
TD { FONT-SIZE: 12px }
TH { FONT-SIZE: 12px }
A:link { TEXT-DECORATION: none }
A:visited { COLOR: #000000; TEXT-DECORATION: none }
A:hover { BACKGROUND-COLOR: #ffccff; TEXT-DECORATION: underline }
A:active { TEXT-DECORATION: none }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" runat="server">
<asp:datalist id="DataList1" style="Z-INDEX: 101; LEFT: 0px; POSITION: absolute; TOP: 0px" Width="472px"
runat="server">
<headertemplate>
<table width="490" border="1" cellpadding="0" cellspacing="0" bordercolor="#ff9933" bordercolordark="#ffffff">
<tr width="490">
<td colspan="4"><p align="center"><font color="#000000">>>分页</font> <font color="#000000">
<asp:hyperlink ID="hyperlink1" runat="server"> 首页 </asp:hyperlink>
<asp:hyperlink ID="hyperlink2" runat="server">上一页</asp:hyperlink></font>
<asp:hyperlink ID="hyperlink3" runat="server">下一页</asp:hyperlink>
<asp:hyperlink ID="hyperlink4">尾页</asp:hyperlink><font color="#000000"> 页次:
<asp:label ID="Label1" runat="server"></asp:label>/</font>
<asp:Label ID="label2" runat="server"></asp:Label><font color="#000000">页</font>
<font color="#000000"> 共<b>
<asp:label ID="Label3" runat="server"></asp:label></b>封 <b>15</b>封/页</font>
</p>
</td>
</tr>
<tr>
<td width="90" height="32" bgcolor="#FEFCDA"><div align="center" class="style2">
发 信 人
</div>
</td>
<td width="245" bgcolor="#FEFCDA">
<div align="center" class="style2">标 题
</div>
</td>
<td width="71" bgcolor="#FEFCDA">
<div align="center" class="style2">回复日期
</div>
</td>
<td width="54" bgcolor="#FEFCDA">
<div align="center" class="style2">关 注
</div>
</td>
</tr>
</headertemplate>
<itemtemplate>
<tr onMouseOver="this.style.backgroundColor='#FFD9D9'" onMouseOut="this.style.backgroundColor=''">
<td height="19" align="left"><font color="#3300FF"><a href='<%#databinder.eval(container.dataitem,"id","list.aspx?id={0}")%>'><%#container.dataitem("name")%></a></font></td>
<td align="left"><font color="#3300FF"><a href='<%# DataBinder.Eval(Container.DataItem, "id", "list.aspx?id={0}") %>'><%#container.dataitem("title")%></a></font></td>
<td align="center"><font color="#3300FF"><a href='<%#databinder.eval(container.dataitem,"id","list.aspx?id={0}")%>'><%#container.dataitem("hfdateendtime").toshortdatestring()%></a></font></td>
<td align="center"><font color="#3300FF"><a href='<%#databinder.eval(container.dataitem,"id","list.aspx?id={0}")%>'><%#container.dataitem("hits")%></a></font></td>
</tr>
</itemtemplate>
<footertemplate>
<tr width="490">
<td colspan="4"><p align="center"><font color="#000000">>>分页</font> <font color="#000000">
<asp:hyperlink ID="first" runat="server"> 首页 </asp:hyperlink>
<asp:hyperlink ID="up" runat="server">上一页</asp:hyperlink></font>
<asp:hyperlink ID="down" runat="server">下一页</asp:hyperlink>
<asp:hyperlink ID="last">尾页</asp:hyperlink><font color="#000000"> 页次:
<asp:label ID="pageno" runat="server"></asp:label>/
<asp:Label ID="pagetotal1" runat="server"></asp:Label>页 共<b>
<asp:label ID="total" runat="server"></asp:label></b>封 <b>15</b>封/页</font>
</p>
</td>
</tr>
</TABLE>
</footertemplate>
</asp:datalist>
</form>
</body>
</HTML>
Imports System.Data
Imports System.Data.oledb
Imports System.Web.UI.WebControlsPublic Class maillist
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
Protected WithEvents pagetotal1, pageno, total, label1, label2, label3 As System.Web.UI.WebControls.Label
Protected WithEvents first, up, down, last, hyperlink1, hyperlink2, hyperlink3, hyperlink4 As System.web.ui.webcontrols.HyperLink
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent() End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
binding()
hit()
'在此处放置初始化页的用户代码
End Sub
Sub binding()
Dim con1 As New conclass.conclass
con1.con1.Open()
Dim sql As String
sql = "select id, name,title,hfdateendtime,hits from xx where hf = True order by hfdateendtime"
Dim adapter1 As New OleDbDataAdapter(sql, con1.con1)
Dim dataset11 As New DataSet
adapter1.Fill(dataset11, "xx")
Dim pads As New PagedDataSource
pads.DataSource = dataset11.Tables("xx").DefaultView
pads.AllowPaging = True
pads.PageSize = 15
pagetotal1.Text = pads.PageCount.ToString()
label2.Text = pads.PageCount.ToString
Dim currentpage As Integer
If Not Request.QueryString("page") Is Nothing Then
currentpage = Convert.ToInt32(Request.QueryString("page"))
Else
currentpage = 1
End If
pads.CurrentPageIndex = currentpage - 1
label1.Text = currentpage.ToString
pageno.Text = currentpage.ToString
If Not pads.IsFirstPage Then
up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(currentpage - 1)
hyperlink2.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentpage - 1)
first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1"
End If
If Not pads.IsLastPage Then
down.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentpage + 1)
hyperlink3.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentpage + 1)
last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(pads.PageCount)
End If
If pads.IsFirstPage Then
first.NavigateUrl = ""
hyperlink1.NavigateUrl = ""
End If
If pads.IsLastPage Then
last.NavigateUrl = ""
hyperlink3.NavigateUrl = ""
End If
DataList1.DataSource = pads
DataList1.DataBind()
End Sub
Sub hit()
Dim i As Integer
i = Request.QueryString("id")
Dim sql As String
Dim conn As New conclass.conclass
conn.con1.Open()
sql = "update xx set hits = hits+1 where id=" & i
Dim cmdoledb As New OleDbCommand(sql, conn.con1)
cmdoledb.ExecuteNonQuery()
conn.con1.Close()
End Sub Private Sub DataList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged End Sub
End Class