< %@ import namespace = "system.data.sqlclient" %>
< %@ import namespace = "system.data" %>
<script runat = "เซิร์ฟเวอร์">
Dim Connorthwind เป็น sqlconnection
สลัว strsql เป็นสตริง
สลัว strelect เป็นสตริง
สลัว Intstartindex เป็นจำนวนเต็ม
Dim IntendIndex เป็นจำนวนเต็ม
dim retrecordcount เป็นจำนวนเต็ม
dim cmdsql เป็น sqlcommand
sub page_load
btnfirst.text = "首页"
btnprev.text = "上一页"
btnnext.text = "下一页"
btnlast.text = "末页"
connorthwind = ใหม่ sqlConnection ("เซิร์ฟเวอร์ = 192.168.4.1; uid = sa; pwd = 111111; ฐานข้อมูล = yourdbname")
ถ้าไม่ใช่ ispostback แล้ว
binddatagrid
สิ้นสุดถ้า
สิ้นสุดย่อย
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 ()
IntrecordCount = DTRRECORDCOUNT (0)
สิ้นสุดในขณะที่
dgrdproducts.virtualitemcount = (recordcount / dgrdproducts.pagesize)
dtrrecordcount.nextresult ()
dgrdproducts.datasource = dtrrecordCount
dgrdproducts.databind ()
Connorthwind.close ()
สิ้นสุดย่อย
sub dgrdproducts_pageindexchanged (s เป็นวัตถุ, e เป็น dataGridPageChangedEventArgs)
intstartindex = e.newPageIndex
dgrdproducts.currentPageIndex = e.newPageIndex
binddatagrid
สิ้นสุดย่อย
subpagerbuttonclick (Byval ผู้ส่งเป็นวัตถุ, byval e เป็น eventargs)
dim arg เป็น string = sender.commandargument
เลือก Case arg
กรณี "ถัดไป"
if (dgrdproducts.currentPageIndex <(dgrdproducts.pagecount - 1)) จากนั้น
dgrdproducts.currentPageIndex += 1
สิ้นสุดถ้า
กรณี "prev"
ถ้า (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 เป็นวัตถุ, e เป็น dataGridCommandEventArgs)
dgrdproducts.edititemindex = e.item.itemindex
intstartindex = dgrdproducts.currentPageIndex
binddatagrid
สิ้นสุดย่อย
sub dgrdproducts_updateCommand (s เป็นวัตถุ, e เป็น dataGridCommandEventArgs)
สลัว intarticleid เป็นจำนวนเต็ม
dim txttopic เป็นกล่องข้อความ
dim txteditor เป็นกล่องข้อความ
สลัว strtopic เป็นสตริง
Dim Streditor เป็นสตริง
intarticleid = dgrdproducts.datakeys (e.item.itemindex)
txttopic = e.item.cells (1). การควบคุม (0)
txteditor = e.item.cells (2). การควบคุม (0)
strtopic = txttopic.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 dgrdproducts_cancelcommand (s เป็นวัตถุ, e เป็น dataGridCommandEventArgs)
dgrdproducts.editItemindex = -1
binddatagrid
สิ้นสุดย่อย
</script>
<html>
<head> <title> dataGridCustompaging.aspx </title> </head>
<body>
<form runat = "เซิร์ฟเวอร์">
<asp: dataGrid runat = "เซิร์ฟเวอร์"
id = "dgrdproducts"
oneditCommand = "dgrdproducts_editcommand"
onUpDateCommand = "dgrdproducts_updateCommand"
onCancelCommand = "dgrdproducts_cancelcommand"
datakeyfield = "a_articleid"
AutogenerAtecolumns = "False"
Showheader = "True"
lewlowpaging = "true"
อนุญาตให้ใช้งาน = "จริง"
HeaderStyle-BackColor = "Salmon"
PAGESIZE = "10"
onPageIndExChanged = "dgrdproducts_pageindexchanged"
PagerStyle-mode = "NumerICPages"
STERVERATIONATIONTEMSTYLE-BACKCOLOR = "#EEAAEE"
font-size = "10pt"
font-name = "verdana"
cellspacing = "0"
CellPadding = "3"
gridlines = "ทั้งสอง"
Borderwidth = "1"
BorderColor = "Black"
Pagerstyle-Horizontalalign = "Right">
<soldnatingItemstyle backcolor = "#eeeeeee"> </surgentatingItemstyle>
<คอลัมน์>
<asp: Boundcolumn
headertext = "序列号"
datafield = "articleid"
อ่านอย่างง่าย ๆ = "true" />
<asp: Boundcolumn
headertext = "标题"
datafield = "topic" />
<asp: Boundcolumn
headertext = "编辑者"
datafield = "editor" />
<ASP: EditCommandColumn
editText = "แก้ไข!"
updateTetext = "อัปเดต!"
canceltext = "ยกเลิก!" -
<ASP: HyperlinkColumn
headertext = "编辑"
datanavigateurlfield = "articleid"
datanavigateUrlFormatString = "details.aspx? id = {0}"
text = "编辑"/>
</คอลัมน์>
</asp: dataGrid>
<ASP: LinkButton ID = "btnfirst" runat = "เซิร์ฟเวอร์" font-name = "verdana" font-size = "8pt" porecolor = "Navy" Commandargument = "0"> </asp: linkbutton> & nbsp;
<ASP: LinkButton ID = "btnprev" runat = "เซิร์ฟเวอร์" font-name = "verdana" font-size = "8pt" porecolor = "Navy" Commandargument = "prev"> </asp: linkbutton> & nbsp;
<ASP: LinkButton ID = "BTNNEXT" runat = "เซิร์ฟเวอร์" font-name = "verdana" font-size = "8pt" porecolor = "Navy" Commandargument = "next"> </asp: linkbutton> & nbsp;
<asp: linkbutton id = "btnlast" runat = "เซิร์ฟเวอร์" font-name = "verdana" font-size = "8pt" porecolor = "Navy" Commandargument = "สุดท้าย"> </asp: linkbutton>
</form>
</html>
下面是存储过程:
สร้างขั้นตอนการรายงานข่าว
-
@PageIndex int,
@Pagesize int
-
เช่น
เริ่ม
ประกาศ @pagelowerbound int
ประกาศ @pageupperbound int
ประกาศ @RowStoreturn int
- แรกตั้งค่า rowcount
ตั้งค่า @RowStorEturn = @Pagesize * (@PePageIndex + 1)
ตั้งค่า rowcount @RowStorEturn
- ตั้งค่าขอบเขตหน้า
ตั้งค่า @PageLowerBound = @Pagesize * @PageIndex
SET @PageUPPERBOUND = @PageLowerBound + @PageSize + 1
- สร้างตารางอุณหภูมิเพื่อจัดเก็บผลลัพธ์ที่เลือก
สร้างตาราง #PageIndex
-
INDEXID INTE IDESTITY (1, 1) ไม่ใช่ NULL
บทความ INT
-
- แทรกลงในตารางอุณหภูมิ
แทรกลงใน #PageIndex (บทความ RECTION)
เลือก
บทความ
จาก
ชื่อแท็บเลน
สั่งโดย
บทความ Desc
- จำนวนผลตอบแทนทั้งหมด
เลือกนับ (บทความทิด) จากชื่อ tablename
- ส่งคืนผลลัพธ์หน้าเพจ
เลือก
O.articleid, O.Topic, Editor
จาก
Tablename o
#PageIndex PageIndex
ที่ไหน
o.articleid = pageindex.articleid และ
pageindex.indexid> @pagelowerbound และ
pageindex.indexid <@pageupperbound
สั่งโดย
pageindex.indexid
จบ