<% @ Importer namespace = "System.Data.SqlClient"%>
<% @ Importer namespace = "System.Data"%>
<script runat = "server">
Dim Connorthwind comme sqlconnection
DIM STRSQL comme chaîne
Dim Strselect comme chaîne
Dim IntstarTindex comme entier
Dim IntendIndex comme entier
Dim intrecordCount comme entier
DIM CMDSQL comme sqlcommand
sous-page_load
btnfirst.text = "首页"
btnprev.text = "上一页"
btnnext.text = "下一页"
btnlast.text = "末页"
Connorthwind = new SqlConnection ("Server = 192.168.4.1; uid = sa; pwd = 111111; database = yourdbname")
Si ce n'est pas un iSpostback, alors
binddatagrid
terminer si
Sub-Sub
sub binddatagrid
cmdSelect dim comme sqlcommand
DIM DTRRRECORDCOUNT comme SQLDATAREADER
IntendIndex = dgrdProducts.pagesize
cmDelect = new SqlCommand ("Newspaged", Connorthwind)
cmdSelect.CommandType = CommandType.StoredProcedure
cmdSelect.Parameters.add ("@PageIndex", IntStarTindex)
cmdSelect.Parameters.add ("@PageSize", IntendIndex)
Connorthwind.open ()
DTRRRECORDCOUNT = CMDSELECT.EXECUTEREDER ()
tandis que dtrrecordCount.read ()
IntrecordCount = dtrrecordCount (0)
terminer
DGRDPRODUCTS.VirtualItemCount = (IntrecordCount / DGRDProduct.Pagesize)
dtrrecordCount.NextResult ()
dgrdProducts.datasource = dtrrecordCount
dgrdProducts.databind ()
Connorthwind.close ()
Sub-Sub
sub dgrdproducts_pageIndexchanged (s comme objet, e comme dataGridpageChangeDeventargs)
IntStarTindex = E.NewPageIndex
dgrdproduct.currentPageIndex = e.newPageIndex
binddatagrid
Sub-Sub
Sub PagerbuttonClick (ByVal Sender comme objet, Byval E comme EventArgs)
Dim Arg as String = Sender.Commandargument
Sélectionnez Case Arg
cas "Suivant"
if (dgrdproducts.currentPageIndex <(dgrdproducts.pageCount - 1)) puis
dgrdproduct.currentPageIndex + = 1
terminer si
cas "prev"
if (dgrdproducts.currentPageIndex> 0) alors
dgrdproducs.currentPageIndex - = 1
terminer si
cas "dernier"
dgrdproducs.currentPageIndex = (dgrdproducts.pageCount - 1)
cas d'autre
'Numéro de page
dgrdProducs.currentPageIndex = System.Convert.Toint32 (Arg)
fin de sélection
IntStarTindex = dgrdProducts.currentPageIndex
binddatagrid
Sub-Sub
sub dgrdproducts_editcommand (s comme objet, e comme dataGridCommandeventArgs)
dgrdproducts.editItemindex = e.item.iteMindex
IntStarTindex = dgrdProducts.currentPageIndex
binddatagrid
Sub-Sub
sub dgrdproducts_updatecommand (s comme objet, e comme dataGridCommandeventArgs)
Dim intarticleid comme entier
Dim txtTopic comme zone de texte
txteditor dim comme zone de texte
Dim strtopic comme chaîne
Dim Streditor comme chaîne
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 = "Update tb_article set [e-mail protégé]," _
& "[e-mail protégé] où [e-mail protégé]"
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
Sub-Sub
sub dgrdproducts_cancelcommand (s comme objet, e comme dataGridCommandeventArgs)
dgrdproducts.editItemindex = -1
binddatagrid
Sub-Sub
</cript>
<html>
<A-Head> <Title> DataGridCustomPaging.aspx </Title> </ Head>
<body>
<form runat = "server">
<asp: datagrid runat = "serveur"
id = "dgrdProducts"
OneDitCommand = "DGRDPRODUCTS_EDITCommand"
onupdatecommand = "dgrdproducts_updatecommand"
oncancelcommand = "dgrdproducts_cancelcommand"
datakeyfield = "a_articleid"
autogenerateColumns = "false"
showheader = "true"
allowpaging = "true"
allowCustomPaging = "true"
Headerstyle-BackColor = "Salmon"
pagesize = "10"
onPageIndexchanged = "dgrdProducts_pageIndexchanged"
pagerrstyle-mode = "NumericPages"
alternativeItemStyle-BackColor = "# eaaee"
font-size = "10pt"
font-name = "Verdana"
CellSpacing = "0"
CellPadding = "3"
gridlines = "les deux"
BorderWidth = "1"
BorderColor = "Black"
pagerrstyle-horizontalalign = "droite">
<alternativeItemStyle backcolor = "# eeeeee"> </ alteratingitemStyle>
<colonnes>
<asp: BoundColumn
headertext = "序列号"
datafield = "ArticleId"
readonly = "true" />
<asp: BoundColumn
headertext = "标题"
datafield = "topic" />
<asp: BoundColumn
headertext = "编辑者"
datafield = "éditeur" />
<asp: editCommandColumn
editText = "Edit!"
updateText = "Update!"
CancelText = "Annuler!" />
<asp: hyperlinkcomnumn
headertext = "编辑"
datanavigateUrlfield = "ArticleId"
datanavigateUrlformatString = "Details.aspx? id = {0}"
text = "编辑" />
</ colonnes>
</ ASP: DataGrid>
<asp: linkButton id = "btnfirst" runat = "server" font-name = "verdana" font-size = "8pt" perfecolor = "navy" commandargument = "0"> </ asp: linkButton> & nbsp;
<asp: linkButton id = "btnprev" runat = "server" font-name = "verdana" font-size = "8pt" perfecor = "NAVY" commandargument = "prev"> </ asp: linkbutton> & nbsp;
<asp: linkbutton id = "btnnext" runat = "server" font-name = "verdana" font-size = "8pt" giftcolor = "navy" commandargument = "net"> </ asp: linkbutton> & nbsp;
<asp: linkbutton id = "btnlast" runat = "server" font-name = "verdana" font-size = "8pt" gifcor = "navy" commandargument = "last"> </ asp: linkButton>
</ form>
</html>
:
Créer des journaux procédures
(
@PageIndex int,
@PageSize int
)
comme
commencer
déclarer @pagelowerbound int
déclarer @pageupperbound int
déclarer @RowstoreRurn int
- Définissez d'abord le rowCount
SET @RowStoreTurn = @PageSize * (@PageIndex + 1)
Définir RowCount @RowStoreTurn
- Définissez les limites de la page
Définissez @PageLowerBound = @PageSize * @PageIndex
set @PageUpperBound = @PageLowerBound + @PageSize + 1
- Créez une table temporaire pour stocker les résultats sélectionnés
Créer la table #PageIndex
(
INDEXID INT Identité (1, 1) pas nul,
ArticleId int,
)
- insérer dans la table temporaire
Insérer dans #PageIndex (articleID)
sélectionner
article
depuis
nom de table
commander
ArticalId Desc
- Retourner le nombre total
Sélectionnez Count (ArticleId) dans TableName
- Retourne les résultats de la pagie
sélectionner
O.articleid, O.Topic, éditeur
depuis
Tablename o,
#PageIndex PageIndex
où
o.articleId = pageIndex.articleId et
pageIndex.Indexid> @pageLowerBound et
PageIndex.Indexid <@PageUpperBound
commander
pageIndex.indexid
fin