<%@ import namespace =“ system.data.sqlclient”%>
<%@ import namespace =“ system.data”%>
<script runat =“ server”>
Dim Connorthwind作為SQLConnection
DIM STRSQL作為字符串
昏暗的stslect作為字符串
Dim IntstartIndex作為整數
Dim IntendIndex作為整數
DIM IntecorDcount作為整數
DIM CMDSQL為SQLCOMMAND
sub page_load
btnfirst.text =“首頁”
btnprev.text =“上一頁”
btnnext.text =“下一頁”
btnlast.text =“末頁”
connorthWind = new sqlConnection(“ server = 192.168.4.1; uid = sa; pwd = 111111; database = yourdbname'')
如果不是Ispostback,則
binddatagrid
如果結束
結束子
sub binddatagrid
DIM CMDSELECT作為SQLCommand
昏暗的dtrrecordcount作為sqldatareader
InvendIndex = dgrdproducts.pagesize
cmdselect = new SQLCommand(“報紙”,ConnorthWind)
cmdselect.commandType = commandType.storedProcedure
cmdselect.parameters.add(“ @pageindex”,intstartindex)
cmdselect.parameters.add(“ @pagesize”,IntendIndex)
connorthwind.open()
dtrrecordCount = cmdselect.executereader()
而dtrrecordcount.read()
InterCordCount = dtrrecordCount(0)
結束
dgrdproducts.virtualitemcount =(intecordCount / dgrdproducts.pageize)
dtrrecordcount.nextresult()
dgrdproducts.datasource = dtrrecordCount
dgrdproducts.databind()
connorthwind.close()
結束子
sub dgrdproducts_pageIndexchanged(s作為對象,e為datagridpagechangedeventargs)
intstartindex = e.newpageIndex
dgrdproducts.currentPageIndex = e.newPageIndex
binddatagrid
結束子
sub pagerbuttonclick(byval發件人作為對象,byval e作為evensargs)
dim arg as string = sender.commandargument
選擇案例arg
案例“下一個”
if(dgrdproducts.currentpageIndex <(dgrdproducts.pagecount -1))然後
dgrdproducts.currentPageIndex += 1
如果結束
案例“上一條”
if(dgrdroducts.currentpageIndex> 0),然後
dgrdproducts.currentPageIndex- = 1
如果結束
案例“最後”
dgrdproducts.currentpageIndex =(dgrdproducts.pagecount -1)
其他情況
'頁碼
dgrdproducts.currentpageIndex = system.convert.toint32(arg)
結束選擇
intstartIndex = dgrdproducts.currentPageIndex
binddatagrid
結束子
sub dgrdproducts_editcommand(s作為對象,e為datagridcommandeventargs)
dgrdproducts.edititemindex = e.item.itemindex
intstartIndex = dgrdproducts.currentPageIndex
binddatagrid
結束子
sub dgrdproducts_updatecommand(s作為對象,e為datagridCommandeventargs)
昏暗的intarticleId作為整數
昏暗的txttopic作為文本框
DIM TXTEDITOR作為文本框
昏暗的strtopic作為字符串
Dim Streditor作為字符串
intarticleId = dgrdproducts.datakeys(e.item.itemindex)
txtttopic = e.item.cells(1).Controls(0)
txteditor = e.item.cells(2).Controls(0)
strtopic = txtttopic.text
streditor = txteditor.text
strsql =“更新tb_article集[電子郵件保護],” _
&“ [電子郵件受保護] [電子郵件保護]
CMDSQL =新的SQLCommand(strsql,ConnorthWind)
cmdsql.parameters.add(“ @topic”,strtopic)
cmdsql.parameters.add(“ @Editor”,Streditor)
cmdsql.parameters.add(“ @articleId”,intarticleId)
connorthwind.open()
cmdsql.executenonquery()
connorthwind.close()
dgrdproducts.edititemindex = -1
binddatagrid
結束子
sub dgrdroducts_cancelCommand(s作為對象,e為datagridCommandeventargs)
dgrdproducts.edititemindex = -1
binddatagrid
結束子
</script>
<html>
<head> <title> datagridcustompogging.aspx </title> </head>
<身體>
<form unat =“ server”>
<asp:datagrid runat =“ server”
id =“ dgrdproducts”
OnEditCommand =“ dgrdproducts_editCommand”
onupdatecommand =“ dgrdproducts_updatecommand”
oncancelCommand =“ dgrdproducts_cancelCommand”
datakeyfield =“ a_articleId”
autogeneratecolumns =“ false”
showheader =“ true”
允許=“ true”
允許施加=“ true”
headerstyle-backcolor =“鮭魚”
pageize =“ 10”
OnPageIndexChanged =“ dgrdproducts_pageindexchanged”
pagerstyle mode =“ numericpages”
交替的ITEMSTYLE-BACKCOLOR =“#EEAAEE”
字體大小=“ 10pt”
font-name =“ verdana”
CellSpacing =“ 0”
cellpadding =“ 3”
網格線=“兩個”
borderwidth =“ 1”
bordercolor =“黑色”
pagerstyle-horizontalalign =“ right”>
<交替的Itemstyle backcolor =“#eeeeee”> </verneratingItemstyle>
<列>
<asp:boundcolumn
headertext =“序列號”
datafield =“ aprentId”
readonly =“ true” />
<asp:boundcolumn
headertext =“標題”
datafield =“ topic” />
<asp:boundcolumn
headertext =“編輯者”
dataField =“編輯器” />
<asp:editCommandColumn
deDittext =“ edit!”
updateText =“ update!”
cancelText =“取消!” />
<asp:超鏈冠
headertext =“編輯”
datanAvigateUrlfield =“ aTrictId”
datanAvigateUrlformAttring =“ litters.aspx?id = {0}”
text =“編輯”/>
</columns>
</asp:datagrid>
<asp:linkButton id =“ btnfirst” runat =“ server” font-name =“ verdana” font-size =“ 8pt” forecolor =“ navy” commandargument =“ 0”> </asp:linkbutton>&nbsp;
<asp:linkbutton id =“ btnprev” runat =“ server” font-name =“ verdana” font-size =“ 8pt” forecolor =“ navy” commandargument =“ prev”> </asp:linkbutton>&nbsp;
<asp:linkbutton id =“ btnnext” runat =“ server” font-name =“ verdana” font-size =“ 8pt” forecolor =“ navy” commandargument =“ next”> </asp:linkbutton>&nbsp;
<asp:linkButton id =“ btnlast” runat =“ server” font-name =“ verdana” font-size =“ 8pt” forecolor =“ navy” commandargument =“ last”> </asp </asp:linkbutton >
</form>
</html>
下面是存儲過程:
創建報紙的過程
((
@pageindex int,
@pagesize int
)
作為
開始
聲明@PagelowerBound int
聲明@pageupperbound int
聲明@RowStoreturn int
- 首先設置Rowcount
set @rowstoreturn = @pagesize *(@pageindex + 1)
設置RowCount @RowStoreturn
- 設置頁面範圍
set @pagelowerbound = @pagesize * @pageindex
設置@pageupperbound = @pagelowerbound + @pagesize + 1
- 創建一個臨時表來存儲選擇結果
創建表#PageIndex
((
索引int int識別(1,1)而不是null,
ArtentId int,
)
- 插入溫度表中
插入#pageIndex(ArticleID)
選擇
ArticleID
從
tablename
訂購
ARTICED DESC
- 回報總數
從tablename中選擇“計數(ArtifID)”
- 返回分頁結果
選擇
O.ArticleId,O.Topic,編輯
從
tablename o,
#PageIndex PageIndex
在哪裡
o.ArticleId = pageIndex.ticleId和
pageIndex.indexid> @pagelowerbound和
pageIndex.indexid <@pageupperbound
訂購
pageIndex.indexid
結尾