<%@ namespace = "system.data.sqlclient"%>
<%@ Import NameSpace = "System.Data"%>
<スクリプトrunat = "server">
sqlconnectionとしてのDim Connorthwind
文字列としてのdim strsql
ひもとしてdim strsect
整数としてdim intstartindex
dimは整数としてdendindexを意図します
IntegerとしてのDim IntercordCount
sqlcommandとしてのdim cmdsql
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
ifを終了します
End Sub
サブビンダタグリッド
sqlcommandとしてdim cmdselect
sqldatareaderとしてのdtrrecordcount
intendindex = dgrdproducts.pagesize
cmdselect = new sqlcommand( "Newspaged"、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)
whileを終えます
dgrdproducts.virtualitemcount =(introcordcount / dgrdproducts.pagesize)
dtrrecordcount.nextresult()
dgrdproducts.datasource = dtrrecordcount
dgrdproducts.databind()
connorthwind.close()
End Sub
sub dgrdproducts_pageindexchanged(s as object、e as datagridpagechededeventargs)
intstartindex = e.newpageIndex
dgrdproducts.currentPageIndex = e.NewPageIndex
binddatagrid
End Sub
Sub PagerButtonClick(byval Sender as object、byval e as eventargs)
dim arg as string = sender.commandargument
Case argを選択します
ケース「次」
if(dgrdproducts.currentPageIndex <(dgrdproducts.pagecount -1))then
dgrdproducts.currentPageIndex += 1
ifを終了します
ケース「前」
if(dgrdproducts.currentpageindex> 0)then
dgrdproducts.currentPageIndex - = 1
ifを終了します
ケース「最後」
dgrdproducts.currentPageIndex =(dgrdproducts.pagecount -1)
ケース他のケース
'ページ番号
dgrdproducts.currentPageIndex = system.convert.toint32(arg)
[選択]を終了します
intstartindex = dgrdproducts.currentPageIndex
binddatagrid
End Sub
sub dgrdproducts_editcommand(s as object、e as datagridcommandeventargs)
dgrdproducts.edititemindex = e.item.itemindex
intstartindex = dgrdproducts.currentPageIndex
binddatagrid
End Sub
sub dgrdproducts_updatecommand(s as object、e as datagridcommandeventargs)
整数としてdim intarticleid
テキストボックスとしてdimtxttopic
TextBoxとしてDIM TXTEDITOR
文字列として薄暗いストロピック
文字列としての薄暗いストレジター
intarticleId = dgrdproducts.datakeys(e.item.itemindex)
txttopic = e.item.cells(1).controls(0)
txteditor = e.item.cells(2).controls(0)
strtopic = txttopic.text
streditor = txteditor.text
strsql = "更新tb_article set [電子メール保護]、" _
&「[電子メール保護]ここで[電子メール保護]」
cmdsql = new 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
End Sub
sub dgrdproducts_cancelcommand(s as object、e as datagridcommandeventargs)
dgrdproducts.edititemindex = -1
binddatagrid
End Sub
</script>
<html>
<head> <title> datagridcustompaging.aspx </title> </head>
<body>
<form runat = "server">
<asp:datagrid runat = "server"
id = "dgrdproducts"
oneditcommand = "dgrdproducts_editcommand"
onupdatecommand = "dgrdproducts_updatecommand"
oncancelcommand = "dgrdproducts_cancelcommand"
datakeyfield = "a_articleid"
autogeneratecolumns = "false"
showheader = "true"
appospaging = "true"
Allowcustompaging = "true"
HeaderSyle-BackColor = "Salmon"
pagesize = "10"
onpageIndExchanged = "dgrdproducts_pageindexchanged"
pagerstele-mode = "numericpages"
AlternatingItemStyle-BackColor = "#eeaaee"
font-size = "10pt"
font-name = "Verdana"
cellspacing = "0"
CellPadding = "3"
gridlines = "両方"
borderwidth = "1"
bordercolor = "black"
PagerSyle-HorizontalAlign = "right">
<allatingItemstyle backcolor = "#eeeeee"> </alternatingemstyle>
<columns>
<ASP:BoundColumn
headertext = "序列号"
datafield = "articleid"
readonly = "true" />
<ASP:BoundColumn
headertext = "标题"
datafield = "topic" />
<ASP:BoundColumn
headertext = "编辑者"
datafield = "editor" />
<ASP:EditCommandColumn
edittext = "edit!"
updateText = "update!"
canceltext = "cancel!" />
<ASP:HyperLinkColumn
headertext = "编辑"
datanavigateurlfield = "articlid"
datanavigateurlformattring = "details.aspx?id = {0}"
text = "编辑"/>
</列>
</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:linkbutton>
</form>
</html>
下面是存储过程:
新聞を作成した手順を作成します
(
@pageindex int、
@pagesize int
))
として
始める
@pagelowerbound intを宣言します
@pageupperbound intを宣言します
@RowStoreturn int
- 最初にRowCountを設定します
@RowStoreturn = @Pagesize *(@PageIndex + 1)を設定します
rowcount @RowStoreturnを設定します
- ページの境界を設定します
@pagelowerbound = @pagesize * @pageIndexを設定します
@pageupperbound = @pageLowerbound + @pagesize + 1を設定します
- 選択結果を保存するための温度テーブルを作成します
テーブル#PageIndexを作成します
(
indexid int ID(1、1)nullではない、
articleid int、
))
- 一時テーブルに挿入します
#pageIndex(articleID)に挿入
選択します
artured
から
タブネーム
注文
artutid desc
- 合計カウントを返します
TableNameからcount(articled)を選択します
- ページングの結果を返します
選択します
o.articleid、o.topic、編集者
から
タブネームO、
#pageindex pageindex
どこ
o.articleid = pageindex.articleid and
pageindex.indexid> @pagelowerbound and
pageindex.indexid <@pageupperbound
注文
pageindex.indexid
終わり