熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

八天學會ASP.net(7)

2022-06-13   來源: .NET編程 

  第七天

  學習目的學會用DATAGRID分頁顯示

  雖然說DATAGRID的分頁顯示效率不怎麼高但是不管怎麼說它是最方便的分頁顯示對於做一個留言簿還是相當簡單實用的對於啟用分頁功能還有一個重要要求只能在DATADRID控件的數據源實現了ICOLLECTION接口的情況下才能啟用分頁功能而DATAREADER沒有這個接口所以必須使用DATATABLE來代替

<script runat=server language=c#>
void Page_Load()
{
string strConnection=Provider=MicrosoftJetOleDb;Data Source=;
strConnection+=ServerMapPath(guestbookmdb);
OleDbConnection objConnection=new OleDbConnection(strConnection);
OleDbDataAdapter objDataAdapter=new OleDbDataAdapter(select * from guestbookobjConnection);
DataSet objDataSet=new DataSet();
objDataAdapterFill(objDataSet);
dgrdMainDataSource=objDataSet;
dgrdMainDataBind();
}
void dgrdMain_PageIndexChanged(Object sender DataGridPageChangedEventArgs e)
{
dgrdMainCurrentPageIndex = eNewPageIndex;
DataBind();
}
</script>
<html>
<body>
<asp:DataGrid
id=dgrdMain
cellpadding=
showheader=true
borderwidth=
allowpaging=true 啟用分頁功能
pagesize= 每一頁顯示三條記錄
onpageindexchanged=dgrdMain_pageindexchanged 調用第×頁的函數為dgrdMain_PageIndexChanged()
runat=server
/>
</body>
</html>

<script runat=server language=vb>
subPage_Load
dim objConnection as OleDbConnection
dim objDataAdapter as OleDbDataAdapter
dim objDataSet as DataSet
objConnection=new OleDbConnection(Provider=MicrosoftJetOleDb;Data Source=+ServerMapPath(guestbookmdb))
objDataAdapter=new OleDbDataAdapter(select * from guestbookobjConnection)
objDataSet=new DataSet
objDataAdapterFill(objDataSet)
dgrdMainDataSource=objDataSet
dgrdMainDataBind()
end sub
sub dgrdMain_PageIndexChanged(sender as objecte as datagridpagechangedeventargs)
dgrdMainCurrentPageIndex = eNewPageIndex
DataBind
end sub
</script>
<html>
<body>
<asp:DataGrid
id=dgrdMain
cellpadding=
showheader=true
borderwidth=
allowpaging=true 啟用分頁功能
pagesize= 每一頁顯示三條記錄
onpageindexchanged=dgrdMain_pageindexchanged 調用第×頁的函數為dgrdMain_PageIndexChanged()
runat=server
/>
</body>
</html>

  這樣就是最簡單的分頁我們可以用參數pagestylemode=nextprev/numericpages來設定是顯示上一頁下一頁方式還是直接選擇頁面的數字方式來實現頁面跳轉如果是前者我們可以用pagestylenextpagetext來設定包含下一頁鏈接的文本用pagestyleprevpagetext來設定包含上一頁鏈接的文本如果是後者我們可以用PagerStylePageButtonCount來設定在使用省略號之前顯示的頁面編號數量(默認是

  今天就說到這裡明天說一下SESSION和COOKIE


From:http://tw.wingwit.com/Article/program/net/201311/15664.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.