Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2007, 10:09 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yamensaleh
Default database paging using asp table+ oledbdataadapter

hi, i waste 3 days looking to how to implement the paging using the objectdatasource and gridView. then i have this idea, which i wana know if it is good or not, and if there is could be any wrong results.
the idea was, why dont i use the asptable, and the DataAdapter.fill method to fill the table with the records that i want to be viewed.

here is the code
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 = "number"
        theader.Cells.Add(tcheader)
        Table1.Rows.Add(theader)
        theader.BackColor = Drawing.Color.Blue
        Dim tcheader1 As New TableCell()
        tcheader1.Text = "name"
        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 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
''end of code
i added a button to the table so i can view the details of the item i need, and the the dropdownlist is used to navigate the results.

now you need to open this page from another page, to have a results, the page must assign the sql statment to a session variable Session("sql").
i tested this code and it work good and fast.
please tell me if it is ok to use or not

thank you
Yamen Saleh





Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a table in a database using asp Droopy Classic ASP Databases 13 March 15th, 2006 03:12 PM
Displaying multiple records in Table thru Paging? InsouciantCoquette Classic ASP Databases 3 February 9th, 2006 12:14 AM
List Database table through ASP abhisheksud Classic ASP Databases 0 September 5th, 2005 05:10 AM
sybase database with asp Paging shaileshk Classic ASP Databases 2 August 20th, 2005 04:35 AM
Database paging zhuge_liang Classic ASP Basics 1 April 23rd, 2004 03:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.