<script runat="server" language="vb"> subPage_Load dim objConnection as OleDbConnection dim objDataAdapter as OleDbDataAdapter dim objDataSet as DataSet objConnection=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("guestbook.mdb")) objDataAdapter=new OleDbDataAdapter("select * from guestbook",objConnection) objDataSet=new DataSet objDataAdapter.Fill(objDataSet) dgrdMain.DataSource=objDataSet dgrdMain.DataBind() end sub sub dgrdMain_PageIndexChanged(sender as object,e as datagridpagechangedeventargs) dgrdMain.CurrentPageIndex = e.NewPageIndex DataBind end sub </script> <html> <body> <asp:DataGrid id="dgrdMain" cellpadding="1" showheader="true" borderwidth="0" allowpaging="true" 启用分页功能 pagesize="3" 每一页显示三条记录 onpageindexchanged="dgrdMain_pageindexchanged " 调用第×页的函数为dgrdMain_PageIndexChanged() runat="server" /> </body> </html> 这样就是最简单的分页,我们可以用参数pagestyle-mode="nextprev/numericpages"来设定是显示上一页、下一页方式还是直接选择页面的数字方式来实现页面跳转。如果是前者我们可以用pagestyle-nextpagetext来设定包含下一页链接的文本,用pagestyle-prevpagetext来设定包含上一页链接的文本;如果是后者我们可以用PagerStyle-PageButtonCount来设定在使用省略号之前显示的页面编号数量(默认是10) 今天就说到这里,明天说一下SESSION和COOKIE。
|