< %@ import namespace = "system.data.sqlclient" %>
< %@ 가져 오기 네임 스페이스 = "System.Data" %>
<script runat = "Server">
SqlConnection으로 Connorthwind를 Dim
strsql dim strsql
문자열로 dim strelect
정수로 intstartindex를 희미하게합니다
정수로서의 impendindex
정수로 Dim intrecordcount
sqlcommand로 dim cmdsql
하위 페이지 _load
btnfirst.text = "首页"
btnprev.text = "上一页"
btnnext.text = "下一页"
btnlast.text = "末页"
CONTHWIND = 새 SQLConnection ( "Server = 192.168.4.1; UID = SA; PWD = 111111; Database = YourDBname")
그렇다면 iSpostback이 아니라면
binddatagrid
끝 If
종료 서브
하위 바인드 다 그리드
dim cmdselect는 sqlcommand입니다
dim dtrrecordcount로 sqldataReader
intendIndex = dgrdProducts.pagesize
cmdselect = new sqlcommand ( "Newspaged", Connorthwind)
cmdselect.commandtype = commandType.StordProcedure
cmdselect.parameters.add ( "@pageindex", intstartIndex)
cmdselect.parameters.add ( "@pagesize", intendindex)
connorthwind.open ()
dtrrecordCount = cmdselect.executereader ()
dtrrecordCount.read ()
intrecordCount = dtrrecordCount (0)
끝을 끝내십시오
dgrdProducts.VirtualItemCount = (intrecordCount / dgrdProducts.pagesize)
dtrrecordCount.nextresult ()
dgrdproducts.datasource = dtrrecordCount
dgrdproducts.databind ()
connorthwind.close ()
종료 서브
sub dgrdProducts_PageIndexChanged (s as 객체, e as as as as as as as as as as as as as as as as as as as as as as as as as as as as)
intstartIndex = e.newpageIndex
dgrdProducts.currentPageIndex = E.NewPageIndex
binddatagrid
종료 서브
Sub PagerButtonClick (Byval 발신자 객체, Byval e as Eventargs)
dim arg as string = sender.commandargument
Case Arg를 선택하십시오
"다음"사례
if (dgrdProducts.currentPageIndex <(dgrdProducts.pageCount -1))
dgrdProducts.currentPageIndex += 1
끝 If
사례 "이전"
if (dgrdProducts.currentPageIndex> 0)
dgrdProducts.currentPageIndex- = 1
끝 If
"마지막"사례
dgrdProducts.currentPageIndex = (dgrdProducts.PageCount -1)
다른 경우
'페이지 번호
dgrdProducts.currentPageIndex = System.Convert.Toint32 (arg)
종료 선택
intstartIndex = dgrdProducts.currentPageIndex
binddatagrid
종료 서브
sub dgrdproducts_editcommand (s as object, e as as as as as as as as as as as as as)
dgrdproducts.editemindex = e.item.itemindex
intstartIndex = dgrdProducts.currentPageIndex
binddatagrid
종료 서브
sub dgrdproducts_updatecommand (s as object, e as as as as as as as as as as as as)
정수로서의 imtarticleid
텍스트 상자로 txttopic을 희미하게합니다
txteditor를 텍스트 상자로 희미하게합니다
문자열로 희미한 strtopic
문자열로 희미한 스트레적
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.editemindex = -1
binddatagrid
종료 서브
sub dgrdproducts_cancelcommand (s as object, e as as as as as as as as as as as as)
dgrdproducts.editemindex = -1
binddatagrid
종료 서브
</스크립트>
<html>
<head> <title> DataGridCusting.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"
alevingpaging = "true"
허용 customging = "true"
Headerstyle-BackColor = "Salmon"
pagesize = "10"
OnPageIndexChanged = "dgrdProducts_PageIndexChanged"
Pagerstyle-Mode = "NumericPages"
교대로서 BackColor = "#eeaaee"
font-size = "10pt"
font-name = "Verdana"
CellSpacing = "0"
CellPadding = "3"
그리드 라인 = "둘 다"
borderwidth = "1"
BorderColor = "Black"
Pagerstyle-Horizontalalign = "Right">
<AlternatingItemStyle BackColor = "#eeeeee"> </allatingItemStyle>
<칼럼>
<ASP : BoundColumn
HeaderText = "xt"
datafield = "articleId"
readonly = "true" />
<ASP : BoundColumn
HeaderText = "xt"
Datafield = "Topic" />
<ASP : BoundColumn
HeaderText = "xt"
datafield = "편집기" />
<ASP : editCommandColumn
editText = "편집!"
updatetext = "업데이트!"
취소 텍스트 = "취소!" />
<ASP : HyperLinkColumn
HeaderText = "xt"
datanavigateUrlfield = "articleId"
datanavigateUrlformatstring = "details.aspx? id = {0}"
텍스트 = "/"/>
</열>
</asp : datagrid>
<asp : linkbutton id = "btnfirst"runat = "server"font-name = "Verdana"font-size = "8pt"forporolor = "navy"commandargument = "0"> </asp : linkbutton> & nbsp;
<asp : linkbutton id = "btnprev"runat = "server"font-name = "Verdana"font-size = "8pt"forporolor = "navy"commandargument = "prev"> </asp : linkbutton> & nbsp;
<asp : linkbutton id = "btnnext"runat = "server"font-name = "Verdana"font-size = "8pt"forporolor = "navy"commandargument = "next"> </asp : linkbutton> & nbsp;
<asp : linkbutton id = "btnlast"runat = "server"font-name = "Verdana"font-size = "8pt"forporolor = "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 Identity (1, 1) null,
articleid int,
))
- 임시 테이블에 삽입하십시오
#PageIndex (articleID)에 삽입
선택하다
articleid
~에서
표정
주문
articleid desc
- 총 카운트를 반환합니다
TableName에서 Count (article)를 선택하십시오
- 반환 페인트 결과
선택하다
O.Articleid, O.Topic, 편집자
~에서
Tablename O,
#PageIndex PageIndex
어디
O.ArticleId = PageIndex.ArticleId 및
pageindex.indexid> @pagelowerbound 및
pageindex.indexid <@pageupperbound
주문
pageindex.indexid
끝