I am working to create a customize paging using oracle database.My code is only gives me the first 20 records from the database and I know because everytime it loads it get the value 20 and it does not show the paging number. I would like to have the paging to be displayed in the first page and the gridview to show the next 20 items every time I change the page nubmer. How can I do this.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Sub BindData()
Dim pageSize As Integer = 20
Dim UpperRowNumber As Integer = ((gvItem.PageIndex + 1) * pageSize) + 1
Dim LowerRowNumber As Integer = (((gvItem.PageIndex + 1) - 1) * pageSize) + 1
Label1.Text = gvItem.PageIndex + 1
Label2.Text = gvItem.PageCount
Dim connectionString As String = ConnectionStrings("ConnectionString").ConnectionString
Dim oOracleConn As OracleConnection = New OracleConnection(connectionString)
oOracleConn.Open()
Dim strStringBuilder As StringBuilder
strStringBuilder = New StringBuilder
With strStringBuilder
.Append("SELECT b.*, ROWNUM ")
.Append("FROM (SELECT a.*, func_get_unit_name (unit_name) plan_unit_description, ROWNUM r__ ")
.Append("FROM (SELECT (SUBSTR (item, 1, 4) || '.' || SUBSTR (item, 5) ) item_number, ")
.Append(" idescr short_description, idescrl long_description, ")
.Append(" iunits unit_name, ispecyr spec_year, iobselet, item ")
.Append("FROM(itemlist) ")
.Append("WHERE item <> '2999509/00001' ")
.Append(" AND iobselet = 'N' ")
.Append(" AND ispecyr = '05' ")
.Append(" ORDER BY item) a ")
.Append(" WHERE ROWNUM < (:rownumberA)) b ")
.Append(" WHERE r__ >= :rownumberB ")
End With
'CREATE A NEW COMMAND AND PASS THE SQL STATEMENT / CONNECTION OBJECT
Dim cmdItemDetail As OracleCommand = New OracleCommand()
cmdItemDetail.Parameters.Add(":rownumberA", OracleType.Int32).Value = UpperRowNumber
cmdItemDetail.Parameters.Add(":rownumberB", OracleType.Int32).Value = LowerRowNumber
cmdItemDetail.Connection = oOracleConn
cmdItemDetail.CommandType = CommandType.Text
cmdItemDetail.CommandText = strStringBuilder.ToString
' Dim adItemDetail As New OleDbDataAdapter(cmdItemDetail)
Dim adItemDetail As New OracleDataAdapter(cmdItemDetail)
Dim dsItemDetail As New DataSet
'Fill the dataset with the result of our query from the specified command
adItemDetail.Fill(dsItemDetail, "ItemDetails")
'Bind the DataSet to the GridView
gvItem.DataSource = dsItemDetail
gvItem.DataBind()
End Sub