[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 775
  • Last Modified:

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?
0
t1clausen
Asked:
t1clausen
1 Solution
 
raterusCommented:
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now