Link to home
Start Free TrialLog in
Avatar of Ramesh Srinivas
Ramesh SrinivasFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of mmarinov
mmarinov

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
Avatar of Ramesh Srinivas

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
Okay, I will give it a go.

thx.
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
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
Okay, I understand the mechanics of what you are saying now - thanks.
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

Never mind, got it!