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?
LVL 2
t1clausenAsked:
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! :-)
0
 
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
            conn.Open()
            cmd.ExecuteReader()
        End Using
        Using conn2
            conn2.Open()
            p = cmd2.ExecuteScalar
        End Using
        FormView2.DataBind()
        FormView2.PageIndex = p - 1
    End Sub
0
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.