?
Solved

Navigating Records Problem

Posted on 2005-03-24
9
Medium Priority
?
202 Views
Last Modified: 2010-04-07
anyone know why the code below does not work?  i have 4 buttons on the form which have the following OnClick values
First onclick="ToFirstRecord"
Previous onclick="ToPreviousRecord"
Next onclick="ToNextRecord"
Last onclick="ToLastRecord"

when i click on the "next" button if goes to the next record.  if i click next again it does not go to the 3rd record.  if i click on any of the other buttons it always ends up going back to the first record.

anyone know whats going on?

Dim m_cnADONetConnection As New SqlConnection
Dim m_daDataAdapter As New SqlDataAdapter
Dim m_dtContacts As New DataTable
Dim m_rowPosition As Integer

sub Page_Load(sender as Object, e as EventArgs)
      m_cnADONetConnection.ConnectionString = "MyconnectionString"
            m_daDataAdapter = New SqlDataAdapter("SELECT * FROM TABLE1",m_cnADONetConnection)

            m_daDataAdapter.Fill(m_dtContacts)

            Me.ShowCurrentRecord()
end sub

Private Sub ShowCurrentRecord()
      If m_dtContacts.Rows.Count = 0 Then
            testbox1.text = ""
            testbox2.text = ""
            Exit Sub
      End If

      testbox1.text = m_dtContacts.Rows(m_rowPosition)("reviewer").ToString()
      testbox2.text = m_dtContacts.Rows(m_rowPosition)("date").ToString()
End Sub

Sub ToFirstRecord(Source as Object, E as EventArgs)
      m_rowPosition = 0
      Me.ShowCurrentRecord()
End Sub

'if not at the first row, go back one row and show the record
Sub ToPreviousRecord(Source as Object, E as EventArgs)
      If m_rowPosition <> 0 Then
            m_rowPosition = m_rowPosition - 1
            Me.ShowCurrentRecord()
      End If
End Sub

'if not on the last row, advance one row and show the record
Sub ToNextRecord(Source as Object, E as EventArgs)
      If m_rowPosition <> (m_dtContacts.Rows.Count - 1) Then
            m_rowPosition = m_rowPosition + 1
            Me.ShowCurrentRecord()
      End If
End Sub

'if there are any rows in the data table, move to the last and show the record
Sub ToLastRecord(Source as Object, E as EventArgs)
      If m_dtContacts.Rows.Count <> 0 then
            m_rowPosition = m_dtContacts.Rows.Count - 1
            Me.ShowCurrentRecord()
      End If
End Sub

thanks
0
Comment
Question by:narmi2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
9 Comments
 
LVL 26

Accepted Solution

by:
Rejojohny earned 200 total points
ID: 13621730
where is m_rowPosition maintained ? it might always contain the value 0 .. so next is moving to the first record (0 + 1) .. and all the other buttons behave in the way u have defined ...
0
 
LVL 6

Assisted Solution

by:dharmesh_amity
dharmesh_amity earned 200 total points
ID: 13623029
Put m_rowPosition in viewstate everytime and get it everytime from viewstate
0
 
LVL 1

Author Comment

by:narmi2
ID: 13636106
about an hour ago it came to me that it will be much better to do this using a datagrid!!!

so i tried it out and it works perfectly.  i will post up the code soon so you all can have a look

thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:narmi2
ID: 13640693
the code

Sub BindData()
      MySQL = "SELECT * from MyTable"

      MyDataSet = new DataSet()
      MyDataAdapter = New SqlDataAdapter(MySQL, MyConn)
      MyDataAdapter.Fill(MyDataSet, "PhotoDataSet")
      
      MyDataGrid.datasource=MyDataSet
      MyDataGrid.datamember="PhotoDataSet"
      
      MyDataGrid.DataBind()
      
      lblCurrentRecord.text = MyDataGrid.CurrentPageIndex + 1
      lblTotalRecords.text = MyDataGrid.pageCount
End Sub

Sub GoToFirstRecord(sender as object, e as eventargs)
      MyDataGrid.CurrentPageIndex = 0
      RecordNumbers()
End Sub

Sub GoToPreviousRecord(sender as object, e as eventargs)
      MyDataGrid.CurrentPageIndex = Math.Max(MyDataGrid.CurrentPageIndex -1,0)
      RecordNumbers()
End Sub

Sub GoToNextRecord(sender as object, e as eventargs)
      MyDataGrid.CurrentPageIndex = Math.Min(MyDataGrid.CurrentpageIndex + 1, MyDataGrid.pageCount - 1)
      RecordNumbers()
End Sub

Sub GoToLastRecord(sender as object, e as eventargs)
      MyDataGrid.CurrentPageIndex = MyDataGrid.PageCount - 1
      RecordNumbers()
End Sub

Sub GoToChosenRecord(sender as object, e as eventargs)
      '## should only allow integers, currently gives an error if not(integers) are typed in!
      if (txtGoTo.text > 0) and (txtGoTo.text <= MyDataGrid.pageCount) then
            MyDataGrid.CurrentPageIndex = txtGoTo.text - 1
            RecordNumbers()
      end if
End Sub

Sub RecordNumbers()
      lblCurrentRecord.text = MyDataGrid.CurrentPageIndex + 1
      lblTotalRecords.text = MyDataGrid.pageCount
      BindData()
End Sub
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13642003
I agree that narmi2 went with a different approach and was able to solve his problem .. but I did spend time trying to understand his old code and commenting on where he has to correct it .. pls comment .,..
0
 
LVL 1

Author Comment

by:narmi2
ID: 13642465
Rejojohny - i have no problem giving you and dharmesh_amity some points if that is possible.  i was not sure what th admin reaction would be.

please advice admin!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 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