• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 809
  • Last Modified:

Help with moving to First and Last Record

Hi,

I am using code below to move to Next and Previous records. How do I modify the code to move to First and Last Records?

Next:

 dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer = Session("currentIndex") + 1
        ViewDataB(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))

Previous:

 dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer
        If Session("currentIndex") >= 1 Then
            rowId = Session("currentIndex") - 1
        Else
            rowId = 0
        End If
        '   ViewDataA(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        Session("currentIndex") = rowId

Victor
0
vcharles
Asked:
vcharles
  • 6
  • 5
  • 2
  • +1
2 Solutions
 
Miguel OzSoftware EngineerCommented:
Can you post ViewDataA and B implementations? I am interrested in the session assignment.
One posible solution
First
dtMaster = Session("dtMaster")
dtKeyMaster = Session("dtKeyMaster")
Dim rowId As Integer = 0
ViewDataB(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
Session("currentIndex")  = 0;

Open in new window

First
dtMaster = Session("dtMaster")
dtKeyMaster = Session("dtKeyMaster")
Dim rowId As Integer =dtKeyMaster.Rows.Count - 1
ViewDataB(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
Session("currentIndex")  = rowId;

Open in new window

0
 
Alan WarrenCommented:
your Next block should probably test for current record being the last record, before navigating to next.

You can use the datatable.rows.rowcount.
        If Session("currentIndex") < dtKeyMaster.Rows.Count - 1 Then
            rowId = Session("currentIndex") + 1
        Else
            rowId = Session("currentIndex") 
        End If

Open in new window

Alan ";0)
0
 
Rajar AhmedConsultantCommented:
Hi ,
    As a continuation of our discussion , You can  replace all Session variable which we used on previous thread to Viewstate  has session can hampers the server memory  when the application grows .

The below code is exactly same as @mas_oz2003 nothing i did except replacement of session to viewstate.
    Protected Sub btnFirst_Click(sender As Object, e As EventArgs)
        dtMaster = ViewState("dtMaster")
        dtKeyMaster = ViewState("dtKeyMaster")
        Dim rowId As Integer = 0
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        ViewState("currentIndex") = rowId
    End Sub
    Protected Sub btnLast_Click(sender As Object, e As EventArgs)
        dtMaster = ViewState("dtMaster")
        dtKeyMaster = ViewState("dtKeyMaster")
        Dim rowId As Integer = dtKeyMaster.Rows.Count - 1
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        ViewState("currentIndex") = rowId
    End Sub

Open in new window

0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
vcharlesAuthor Commented:
Hi,

I replaced session with ViewState for Next, Previous also, but I received the following error:

Object reference not set to an instance of an object.

On line:

ViewDataB(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))


        dtMaster = ViewState("dtMaster")
        dtKeyMaster = ViewState("dtKeyMaster")
        Dim rowId As Integer = Session("currentIndex") + 1
        ViewDataB(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))

Same error occurs with code to MoveFirst.

Any ideas what is causing this error?

Thanks,

V.
0
 
Rajar AhmedConsultantCommented:
this looks like more of generic error, do debug and check whether your getting values for  respective object

ie dtmaster,dtkeymaster,
Also change session("currentindex") to viewstate("currentindex")

Meeran03
0
 
Rajar AhmedConsultantCommented:
Have you change this on Searchfuze1 method?
0
 
vcharlesAuthor Commented:
I did not, will do so in a few minutes. I am only testing three records, but it seems that Session works for going to First and Last. But I will take your advice and try to use ViewState.

Protected Sub btnFirst_Click(sender As Object, e As EventArgs)
        dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer = 0
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        ViewState("currentIndex") = rowId
    End Sub
    Protected Sub btnLast_Click(sender As Object, e As EventArgs)
        dtMaster = Session("dtMaster")
        dtKeyMaster = Session("dtKeyMaster")
        Dim rowId As Integer = dtKeyMaster.Rows.Count - 1
        ViewData(dtKeyMaster.Rows(rowId)(1), dtKeyMaster.Rows(rowId)(2))
        ViewState("currentIndex") = rowId
    End Sub
V.
0
 
vcharlesAuthor Commented:
Did you mean change Session("currentIndex") = 0 to ViewState("currentIndex") = 0?
0
 
Rajar AhmedConsultantCommented:
yes , and also below change respectively,

     ViewState("dtMaster") = dtMaster
        ViewState("dtKeyMaster") = dtKeyMaster
0
 
vcharlesAuthor Commented:
It Works!
Thanks!
V.
0
 
Alan WarrenCommented:
mas_oz2003 got my vote, he clearly answered the question as originally stated: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27833879.html#a38308525

Alan ";0)
0
 
vcharlesAuthor Commented:
Hello,

Sorry, I over looked the initial answer, I would like to split the points (250 each)  between post

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27833879.html#a38308525

and post

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27833879.html#a38309204


Thank  You both for your Help.

Victor
0
 
Rajar AhmedConsultantCommented:
Yes, i deserve only a assisted solution  for this thread.
 
Meeran03
0
 
Miguel OzSoftware EngineerCommented:
the split is OK for me. thanks
0
 
vcharlesAuthor Commented:
Please close this issue. Thank You!
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!

  • 6
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now