Simple DataSet for Paging Instead of ObjectDataSource

I wasted around 3 days searching how to implement a paging results for my search pages, then I think why did not i use the asp table instead of gridview, and use the DataAdapter.fill to fill the datatable with the records i need to be viewd.

Partial Class _Default

Inherits System.Web.UI.Page

Dim dc As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dotnet samples\asp.net\datapager\NWIND.MDB;Persist Security Info=False")

Dim strSQL As String

Dim myDataAdapter As Data.OleDb.OleDbDataAdapter

Dim dstaccounts As New Data.DataSet()

Dim s As Integer

Dim pages As Integer

Dim rowperpages As Integer = 10

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

strSQL = Session("select")

If strSQL <> Nothing Then

myDataAdapter = New Data.OleDb.OleDbDataAdapter(strSQL, dc)

If Not IsPostBack Then

dc.Open()

myDataAdapter.Fill(dstaccounts, "AccountsTable")

Session("s") = dstaccounts.Tables(0).Rows.Count

Session("pages") = Session("s") / rowperpages

If Session("s") - Conversion.Int(Session("pages")) * rowperpages > 0 Then Session("pages") = Session("pages") + 1

Dim i As Integer

For i = 1 To Session("pages")

DropDownList1.Items.Add(i)

Next

dc.Close()

dstaccounts.Clear()

bind_table()

Else

If DropDownList1.Text <> "" Then

Session("hit") = DropDownList1.Text

Else

Session("hit") = 0

End If

bind_table() 'Else

End If

End If

End Sub

Private Sub bind_table()

dc.Open()

Dim x As Integer

x = Session("hit") - 1

If x = -1 Or x = 0 Then

myDataAdapter.Fill(dstaccounts, 0, rowperpages, "AccountsTable")

Else

myDataAdapter.Fill(dstaccounts, x * rowperpages, rowperpages, "AccountsTable")

End If

dc.Close()

Dim ii As Integer

Dim theader As New TableRow

theader.BackColor = Drawing.Color.Blue

Dim tcheader As New TableCell()

tcheader.Text = "الرقم"

theader.Cells.Add(tcheader)

Table1.Rows.Add(theader)

theader.BackColor = Drawing.Color.Blue

Dim tcheader1 As New TableCell()

tcheader1.Text = "الاسم"

theader.Cells.Add(tcheader1)

Table1.Rows.Add(theader)

For ii = 0 To rowperpages

Try

Dim drow As Data.DataRow = dstaccounts.Tables(0).Rows.Item(ii)

Dim tr As New TableRow

Dim tc As New TableCell()

Dim rowcount As Integer

If DropDownList1.Text = 1 Then rowcount = ii + 1 Else rowcount = rowperpages * (DropDownList1.Text - 1) + ii + 1

tc.Text = rowcount

tr.Cells.Add(tc)

''''''

tc = New TableCell()

tc.Text = drow.Item(1).ToString

tr.Cells.Add(tc)

''''''

Dim tc2 As New TableCell()

tc2.Text = drow.Item(2).ToString

tr.Cells.Add(tc2)

tc = New TableCell()

tc.Text = drow.Item(3).ToString & "<br>" & "yamen" & "<BR>" & "nidal"

tr.Cells.Add(tc)

Dim but As New Button

but.Width = 70

but.Visible = True

but.Text = "view pdf"

but.PostBackUrl = "http://www.yahoo.com?x=" & tc.Text

Dim tc3 As New TableCell

tc3.Controls.Add(but)

tr.Cells.Add(tc3)

Table1.Rows.Add(tr)

Catch ex As Exception

End Try

Next

End Sub

Private Function make(ByVal a As String) As String

Response.Redirect(a)

make = "1"

End Function

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

End Sub

End Class

By yamen saleh   Popularity  (2606 Views)