< %@ import namespace = "System.data.sqlclient" %>
< %@ import namespace = "System.data" %>
<script runat = "server">
Dim ConnorthWind как sqlConnection
Dim Strsql как строка
Dim StrseSelet как строка
dim intstartindex как целое число
Dim Intendindex как целое число
Dim IntercordCount как целое число
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
Dim dtrrecordCount как sqldatareader
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)
конец, пока
dgrdproducts.virtualitemcount = (IntercordCount / dgrdProducts.pagesize)
dtrrecordcount.nextresult ()
dgrdproducts.datasource = dtrrecordcount
dgrdproducts.databind ()
connorthwind.close ()
Конец суб
sub dgrdproducts_pageindexchanged (s as object, e как datagridpagechangeventeventargs)
intStartIndex = e.newPageIndex
dgrdProducts.currentPageIndex = e.newPageIndex
BindDataGrid
Конец суб
Sub pagerbuttonclick (Byval Sender как объект, Byval E как события)
Dim arg as string = sender.commandargument
Выберите случай arg
дело "Далее"
if (dgrdproducts.currentpageindex <(dgrdproducts.pagecount - 1)) тогда
dgrdproducts.currentpageindex += 1
конец, если
случай "prev"
if (dgrdproducts.currentpageindex> 0) тогда
dgrdproducts.currentpageindex -= 1
конец, если
Дело "последнее"
dgrdproducts.currentpageindex = (dgrdproducts.pagecount - 1)
случай еще
'номер страницы
dgrdproducts.currentpageindex = System.convert.toint32 (arg)
конец выбора
intStartIndex = dgrdProducts.currentPageIndex
BindDataGrid
Конец суб
sub dgrdproducts_editcommand (s as object, e как datagridcommandeventargs)
dgrdproducts.edititemindex = e.item.itemindex
intStartIndex = dgrdProducts.currentPageIndex
BindDataGrid
Конец суб
sub dgrdproducts_updatecommand (s as object, e как datagridcommandeventargs)
Dim Intarticleid как целое число
Dim txttopic как текстовый поле
Dim txteditor как текстовое поле
Dim Strtopic как строка
Dim Streditor как строка
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 [электронная почта защищена]," _
& "[Электронная почта защищена], где [электронная почта защищена]"
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 dgrdproducts_cancelcommand (s as object, e как datagridcommandeventargs)
dgrdproducts.edititemindex = -1
BindDataGrid
Конец суб
</script>
<html>
<Head> <title> dataGridCustomaping.aspx </title> </head>
<тело>
<form runat = "server">
<asp: datagrid runat = "server"
id = "dgrdproducts"
oneditCommand = "dgrdproducts_editcommand"
onupdatecommand = "dgrdproducts_updatecommand"
oncancelcommand = "dgrdproducts_cancelcommand"
Dataqueyfield = "a_articleid"
AutogenerateColumns = "false"
ShowHeader = "true"
AllyPaging = "true"
AllowCustomaping = "true"
headerstyle-backcolor = "лосось"
PageSize = "10"
OnPageIndExchanged = "dgrdProducts_pageindexchanged"
PagerStyle-Mode = "NUMIRCPAGES"
changeringItemstyle-backcolor = "#eeaaee"
font-size = "10pt"
Font-name = "Verdana"
cell -spacing = "0"
cellPadding = "3"
Gridlines = "Оба"
Borderwidth = "1"
Bordercolor = "Черный"
PagerStyle-horizontalign = "right">
<charictingItemStyle BackColor = "#eeeeee"> </charicingItemStyle>
<столбцы>
<ASP: BoundColumn
headerText = "序列号"
DataField = "articleID"
readonly = "true" />
<ASP: BoundColumn
headerText = "标题"
DataField = "topic" />
<ASP: BoundColumn
headerText = "编辑者"
DataField = "редактор" />
<ASP: EDITCOMMANDCOLUMN
EditText = "Edit!"
UpdateText = "Обновление!"
CancelText = "Cancel!" />
<ASP: HyperlinkColumn
headerText = "编辑"
datanavigateurlfield = "articleid"
datanavigateurlformatstring = "details.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: linkbutton>
</form>
</html>
下面是存储过程 :
Создать процедуру в сборе
(
@pageindex int,
@pagesize int
)
как
начинать
Объявить @PageLowerBound Int
Объявить @PageOpperBound Int
Объявить @rowstoreturn Int
- Сначала установите ряд
SET @RowStorEnurn = @Pagesize * (@PageIndex + 1)
Установите RowCount @RowStorETURN
- Установите границы страницы
SET @PageLowerBound = @Pagesize * @PageIndex
SET @PageOpperBound = @PageLowerBound + @Pagesize + 1
- Создайте таблицу температуры для хранения результатов выбора
Создать таблицу #PageIndex
(
ИНДЕКСИДОВАЯ Идентичность (1, 1) не нулевой,
articleid int,
)
- Вставьте в таблицу температуры
Вставьте в #pageindex (articleid)
выбирать
Статья
от
табличное имя
заказ за
articleid desc
- вернуть общий счет
Выберите счет (articleID) из TableName
- вернуть результаты
выбирать
O.ArticleId, O.Topic, редактор
от
Таблица o,
#pageindex pageindex
где
O.ArticleId = pageIndex.ArticleId и
PageIndex.indexid> @pageLowerBound и
pageindex.indexid <@pageupperbound
заказ за
PageIndex.indexid
конец