datagrid| stored Procedures | pagination | data
<%@ Import namespace= "System.Data.SqlClient"%>
<%@ Import namespace= "System.Data"%>
<script runat= "Server" >
Dim Connorthwind as SqlConnection
Dim Strselect as String
Dim Intstartindex as Integer
Dim Intendindex as Integer
Sub Page_Load
Dim Cmdselect as SqlCommand
Btnfirst.text = "Home"
Btnprev.text = "Previous Page"
Btnnext.text = "Next Page"
Btnlast.text = "Last Page"
Connorthwind = New SqlConnection ("server=192.168.4.1; Uid=sa; Pwd=xxxxxx;database=northwind ")
If not IsPostBack Then
' Get Total Pages
Strselect = "Select COUNT (OrderID) from Orders"
Cmdselect = New SqlCommand (strselect, Connorthwind)
Connorthwind.open ()
Dgrdproducts.virtualitemcount = (Cmdselect.executescalar ()/dgrdproducts.pagesize)
Connorthwind.close ()
Binddatagrid
End If
End Sub
Sub Binddatagrid
Dim Dadproducts as SqlDataAdapter
Dim Dstproducts as DataSet
Intendindex = Dgrdproducts.pagesize
Dadproducts = New SqlDataAdapter ("orderspaged", Connorthwind)
DadProducts.SelectCommand.CommandType = CommandType.StoredProcedure
DADPRODUCTS.SELECTCOMMAND.PARAMETERS.ADD ("@PageIndex", Intstartindex)
DADPRODUCTS.SELECTCOMMAND.PARAMETERS.ADD ("@PageSize", Intendindex)
Dstproducts = New DataSet
Dadproducts.fill (dstproducts)
Dgrdproducts.datasource = dstproducts
Dgrdproducts.databind ()
End Sub
Sub dgrdproducts_pageindexchanged (s as Object, E as DataGridPageChangedEventArgs)
Intstartindex = E.newpageindex
Dgrdproducts.currentpageindex = E.newpageindex
Binddatagrid
End Sub
Sub Pagerbuttonclick (ByVal sender as Object, ByVal e as EventArgs)
Dim arg as String = sender.commandargument
Select Case Arg
Case "Next"
If (Dgrdproducts.currentpageindex < (dgrdproducts.pagecount-1)) Then
Dgrdproducts.currentpageindex + 1
End If
Case "Prev"
If (Dgrdproducts.currentpageindex > 0) Then
Dgrdproducts.currentpageindex-= 1
End If
Case "Last"
Dgrdproducts.currentpageindex = (dgrdproducts.pagecount-1)
Case Else
' Page number
Dgrdproducts.currentpageindex = System.Convert.ToInt32 (ARG)
End Select
Intstartindex=dgrdproducts.currentpageindex
Binddatagrid
End Sub
</Script>
<body>
<form runat= "Server" >
<asp:datagrid runat= "Server"
Id= "Dgrdproducts"
Showheader= "false"
Allowpaging= "True"
Allowcustompaging= "True"
Pagesize= "10"
Onpageindexchanged= "Dgrdproducts_pageindexchanged"
Pagerstyle-mode= "NumericPages"
Alternatingitemstyle-backcolor= "#eeaaee"
Headerstyle-backcolor= "#aaFFdd"
Font-size= "10pt"
Font-name= "Verdana"
cellspacing= "0"
Cellpadding= "3"
Gridlines= "Both"
Borderwidth= "1"
Bordercolor= "BLACK"
Pagerstyle-horizontalalign= "Right" >
<alternatingitemstyle backcolor= "#EEEEEE" ></AlternatingItemStyle>
</asp:datagrid>
<asp:linkbutton id= "Btnfirst" runat= "server" font-name= "Verdana" font-size= "8pt" forecolor= "Navy" CommandArgument = "0" ></asp:linkbutton>
<asp:linkbutton id= "Btnprev" runat= "server" font-name= "Verdana" font-size= "8pt" forecolor= "Navy" commandargument= "Prev" ></asp:linkbutton>
<asp:linkbutton id= "Btnnext" runat= "server" font-name= "Verdana" font-size= "8pt" forecolor= "Navy" commandargument= "Next" ></asp:linkbutton>
<asp:linkbutton id= "Btnlast" runat= "server" font-name= "Verdana" font-size= "8pt" forecolor= "Navy" commandargument= "Last" ></asp:linkbutton>
</form>
The following are stored procedures:
CREATE PROCEDURE orderspaged
(
&nb