Record Navigation....

Hi all,

My grid displays several rows of data. Each row has a link, which when clicked, displays the detail page for that row. What I want is to have a PREVIOUS and NEXT navigation on this detail page, thereby allowing the user to flick back and forth thru the records without having to go back to the master page.

When the link is clicked to jump to the detail page I am not sure how to increment the records from that particular ID.

I would appreciate any help on this,

regards,

KS
LVL 11
Ramesh SrinivasTechnical ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmarinovCommented:
Hi saleek,

i think the scenario should be:
1. in the link of the list page you should include the id of the record
2. also you have to add to a session variable an array of these ids
3. on the detail page, when you have to id of the current record you can search through this array and find the previous/next id and get its data from database

Regards!
B..M
mmarinov
0
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Hi mmarinov,

I am already including the IDs in a hidden column in the grid.

How would I capture the entire list of IDs generated by the dataset? Should I loop through each datarow before binding and store in session var as array?

thanks,

KS
0
mmarinovCommented:
this is one way
another way i've though of is to keeps in a session just the current, previous and next id
this you can get from the itemcommand event before redirecting to the next page
and when you click on previous/next button in the details page by getting the data you can add 2 additional parameters which will be output type and will return the previous and next ids

B..M
mmarinov
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ramesh SrinivasTechnical ConsultantAuthor Commented:
mmarinov,

Could you elaborate on your second idea a bit more please.

How can I navigate all records by just having the previous and next IDs?? I don't quite understand that one.

Thanks for your help,

KS
0
mmarinovCommented:
on your details page you have

details
<       >
where <> are links to the previous/next id, correct ?
so if you have the ids you can to the things

when you click on the link within the list page you pass and id to the current record so you can get the complete info. so i suggest you to get the id from previous and next row in the dataset
then you have these ids

the problem arise with the clicking on the <>, but ... when you get the info from database by the passed id, you can get and the previous and next ids for the passed ids and assign them to the <> links

B..M
mmarinov
0
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Okay, I will give it a go.

thx.
0
Ramesh SrinivasTechnical ConsultantAuthor Commented:
If I am passing the ID from master page, and then fetching the record based on that ID - it will return 1 row - so to get the next and previous IDs I would have to query the database again, passing that same ID and then some how get it to return the row ID-1 and ID+1.

I am having difficulty understanding how this would work.

regards,

KS
0
mmarinovCommented:
you can query the database with a single storedprocedure
define 2 output parameters
perdorm you select statement to get details data
and after then perform select to get the previous and the next ID
in the code behind bind data to datagrid and use the 2 parameters to build the links

B..M
mmarinov
0
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Okay, I understand the mechanics of what you are saying now - thanks.
0
Ramesh SrinivasTechnical ConsultantAuthor Commented:
I have made an SP to output next and previous:

CREATE PROCEDURE [SP_GetNextPreviousPress]

@ID integer,
@Next integer Output,
@Previous integer Output

AS

SELECT @next = MIN(MON_ID)
FROM TBL_Monitored
WHERE MON_ID > @ID

SELECT @previous = MAX(MON_ID)
FROM TBL_Monitored
WHERE MON_ID < @ID
GO


Now I am trying to get the next and previous IDs using a datareader, but seem to be getting the following error:

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'SP_GetNextPreviousPress'.


My ASP.NET code is:

        Dim dr As SqlDataReader

        Dim myConn As New SqlConnection
        myConn = intMed.iMConn
        Dim Cmd As New SqlCommand("[SP_GetNextPreviousPress]", myConn)

        Dim IDParam = New SqlParameter("@ID", SqlDbType.Int)
        IDParam.value = tID
        IDParam.Direction = ParameterDirection.Input
        Cmd.Parameters.Add(IDParam)

        Dim NextID = New SqlParameter("@Next", SqlDbType.Int)
        NextID.Direction = ParameterDirection.Output
        Cmd.Parameters.Add(NextID)

        Dim PrevID = New SqlParameter("@Previous", SqlDbType.Int)
        PrevID.Direction = ParameterDirection.Output
        Cmd.Parameters.Add(PrevID)

        dr = Cmd.ExecuteReader()
        'Cmd.Dispose()

        While dr.Read()
            Session("NextID") = dr(0)
            Session("PrevID") = dr(1)
        End While


What am I doing wrong/not doing? thanks very much.

KS

0
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Never mind, got it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.