Open Formview or detailsview to go to last record

Posted on 2006-05-17
Last Modified: 2008-01-09
By default a child formview (or detailsview) goes to the first record in a table. Can you have it open to the last record instead?
Question by:t1clausen
    LVL 33

    Accepted Solution

    Both DetailsView and FormsView controls have a PageIndex property,

    BEFORE you bind it to the datasource, you need to know the count of the datasource, and set the PageIndex = DataSourceCount - 1

    Just a guess...I've really never done it! :-)
    LVL 2

    Author Comment

    Perfect!!!  Just in case someone wants to see the code....
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim connectionString As String = WebConfigurationManager.ConnectionStrings("adr").ConnectionString
            Dim conn As New SqlConnection(connectionString)
            Dim conn2 As New SqlConnection(connectionString)
            Dim cmd As New SqlCommand("INSERT INTO lines (ADRNumber) VALUES(" & TextBox1.Text & ")", conn)
            Dim cmd2 As New SqlCommand("Select Count (*) from  lines where adrnumber = '" & TextBox1.Text & "'", conn2)
            Dim p As Integer
            Using conn
            End Using
            Using conn2
                p = cmd2.ExecuteScalar
            End Using
            FormView2.PageIndex = p - 1
        End Sub

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now