Open Formview or detailsview to go to last record

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?
Who is Participating?
raterusConnect With a Mentor Commented:
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! :-)
t1clausenAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.