An ASP tutorial. NET GridView Pagination Instance code
This section of the GridView page example, he from the database tutorial to the paging SQL all have, as long as you follow this example to do, you can fully instance asp.net tutorial GridView paging functionality. */
CREATE PROCEDURE [dbo]. [Sp_systemquotationrevisionpaging]
(
@clientid nvarchar (255),
@clientmodel nvarchar (255),
@collection nvarchar (255),
@startindexpage int,
@endindexpage int,
@count int Output
)
As
Select
*
From
(select Row_number () over (order by createddate Desc) as row,* from Quotationrevision
where
Upper (ClientID) like @clientid + '% '
and Upper (Clientmodel) like @clientmodel + '% '
and (Upper ([collection]) like '% ' + @collection + '% '
Or
(@collection = ' ' and [collection] is null)
) quotationrevision
where row between (@endindexpage-1) * @startindexpage +1 and @endindexpage * @startindexpage
Set @count = (select count (*) from quotationrevision
where
Upper (ClientID) like @clientid + '% '
and Upper (Clientmodel) like @clientmodel + '% '
and (Upper ([collection]) like '% ' + @collection + '% '
Or
(@collection = ' ' and [collection] is null)
)
Return
Go
The GridView;
Protected Sub btnSearch_Click (ByVal sender As Object, ByVal e As EventArgs) Handles Btnsearch.click
Generatedata ()
End Sub
Private Sub Generatedata ()
Dim currentpage As Integer
If Request.QueryString ("CurrentPage") is Nothing Then
CurrentPage = 1
Else
CurrentPage = CInt (Request.QueryString ("CurrentPage"))
End If
Dim Strengcode As String = Txtclientid.text.trim
Dim Strerpcode As String = Txtclientmodel.text.trim
Dim strdescription As String = Txtcollection.text.trim
Dim pengcode As New Sqlclient.sqlparameter ("@clientid", SqlDbType.NVarChar)
Dim perpcode As New Sqlclient.sqlparameter ("@clientmodel", SqlDbType.NVarChar)
Dim pdescription As New Sqlclient.sqlparameter ("@collection", SqlDbType.NVarChar)
Dim ppagesize As New Sqlclient.sqlparameter ("@startindexpage", SqlDbType.Int)
Dim pcurrentpage As New Sqlclient.sqlparameter ("@endindexpage", SqlDbType.Int)
Dim pcount As New Sqlclient.sqlparameter ("@count", SqlDbType.Int)
Pengcode.value = Strengcode.toupper ()
Perpcode.value = Strerpcode.toupper ()
Pdescription.value = Strdescription.toupper ()
Ppagesize.value = 10
Pcurrentpage.value = CurrentPage
Pcount.direction = ParameterDirection.Output
Dim da As New Wmo.appobjects.dataaccess
Dim conn As Sqlclient.sqlconnection = Da.conn
Dim cmd As New Sqlclient.sqlcommand ("Sp_systemquotationrevisionpaging", conn)
Cmd.commandtype = CommandType.StoredProcedure
Cmd.parameters.add (Pengcode)
Cmd.parameters.add (Perpcode)
Cmd.parameters.add (pdescription)
Cmd.parameters.add (Ppagesize)
Cmd.parameters.add (Pcurrentpage)
Cmd.parameters.add (Pcount)
Conn.Open ()
Dim reader As Sqlclient.sqldatareader = Cmd.executereader ()
Gv_quotationid.datasource = Reader
Gv_quotationid.databind ()
Reader.close ()
Conn.close ()
Dim count As Integer = CInt (Cmd.parameters ("@count"). Value)
Generatepaging (CurrentPage, 5, Count)
End Sub
Private Sub Generatepaging (ByVal currentpage As Integer, ByVal pagesize As Integer, ByVal maxpage As Integer, ByVal count As Integer)
Dim querystring As String
If Request.querystring.count > 0 Then
Dim indexcurentpage As Integer = Request.url.absoluteuri.indexof ("CurrentPage")
If Indexcurentpage <>-1 Then
QueryString = request.url.absoluteuri.substring (0, Indexcurentpage)
Else
QueryString = Request.url.absoluteuri + "&"
End If
Else
QueryString = Request.url.absoluteuri + "?"
End If
Dim PageCount As Integer
If Count mod pagesize > 0 Then
PageCount = Math.floor (count/pagesize) + 1
Else
PageCount = Math.floor (count/pagesize)
End If
If PageCount > 1 Then
Dim Scopenumber = Math.floor ((currentpage-1)/maxpage)
Dim startnumber As Integer = scopenumber * maxpage + 1
Dim endnumber As Integer
if ((Scopenumber + 1) * Maxpage) < PageCount Then
Endnumber = (scopenumber + 1) * Maxpage
Else
Endnumber = PageCount
End If
Dim table As New Table ()
Dim tr As New TableRow
' Pre page
If currentpage > 1 Then
Dim td As New TableCell
Dim href As New Hyperlink
Href.text = "Previous page www.111cn.net"
Href.navigateurl = querystring + "currentpage=" + (currentpage-1). ToString ()
Td.controls.add (HREF)
Tr.controls.add (TD)
End If
' Pre more
If Scopenumber > 0 Then
Dim td As New TableCell
Dim href As New Hyperlink
Href.text = "..."
Href.navigateurl = querystring + "currentpage=" + ((scopenumber-1) * maxpage + 1). ToString ()
Td.controls.add (HREF)
Tr.controls.add (TD)
End If
' Middle
For i As Integer = Startnumber to Endnumber
Dim td As New TableCell
Dim href As New Hyperlink
Href.text = i
If I <> currentpage then
Href.navigateurl = querystring + "currentpage=" + i.tostring ()
Else
HREF.CSS Tutorial class = "CurrentPage"
End If
Td.controls.add (HREF)
Tr.controls.add (TD)
Next
' Last more
If Endnumber < PageCount Then
Dim td As New TableCell
Dim href As New Hyperlink
Href.text = "..."
Href.navigateurl = querystring + "currentpage=" + (Endnumber + 1). ToString ()
Td.controls.add (HREF)
Tr.controls.add (TD)
End If
' Last number
If Endnumber <> PageCount Then
Dim td As New TableCell
Dim href As New Hyperlink
Href.text = pagecount.tostring ()
Href.navigateurl = querystring + "currentpage=" + pagecount.tostring ()
Td.controls.add (HREF)
Tr.controls.add (TD)
End If
' Last page
If CurrentPage < PageCount Then
Dim td As New TableCell
Dim href As New Hyperlink
Href.text = "Next Page"
Href.navigateurl = querystring + "currentpage=" + (CurrentPage + 1). ToString ()
Td.controls.add (HREF)
Tr.controls.add (TD)
End If
' Go
Dim html = "<a id= ' lnkpage ' style= ' Display:none;" ></a> to <input id= ' Txtpageno ' size= ' 1 ' onblur= ' setpage () '/> page <input type= ' button ' value= ' http:// Www.111cn.net ok ' onclick= ' gopage () '/> '
Dim Tdgo As New TableCell
Tdgo.text = html
Tr.controls.add (Tdgo)
Table.controls.add (TR)
Divpaging.controls.add (table)
End If
End Sub