|
-
May 22nd, 2013, 04:09 AM
#1
Thread Starter
Registered User
Navigating records next/previous
Hi,
I have written a .net web application quite some time ago and now required some enhancement... but I'm now lost on how to do this So appreciate any insights from all of you here.
I have a page (page A) displaying a GridView of records from a SQL table. Upon clicking on a row, user will be lead to another page (page B) displaying the details of the selected record. From page A, I passed the value of a generated ID through querystring to page B, and based on this ID, the application will query the database to fetch all the values and display accordingly in a FormView. Page B will also allow user to edit and update the record.
How is it possible if I want to have the ability to navigate to next/previous record from Page B without having to go back to Page A again?
Appreciate any help! Thanks in advance!! 
Cheers!
-
May 22nd, 2013, 07:55 AM
#2
Re: Navigating records next/previous
Hey,
Is it possible that you can show the URL that you pass into the details page?
It might be as simple as looking at the id parameter that you pass in, and then constructing a new URL, in the form of a hyperlink, with the same URL, with the Id decremented and incremented by 1.
Gary
-
May 22nd, 2013, 07:56 AM
#3
Re: Navigating records next/previous
Assuming that you have increasing numeric IDs, you can find the next record like this:
sql Code:
SELECT TOP 1 * FROM MyTable WHERE ID > @ID
and you pass the ID of the current record to the @ID parameter. The previous record is similar:
sql Code:
SELECT TOP 1 * FROM MyTable WHERE ID < @ID ORDER BY ID DESC
-
May 22nd, 2013, 07:58 AM
#4
Re: Navigating records next/previous
 Originally Posted by gep13
Hey,
Is it possible that you can show the URL that you pass into the details page?
It might be as simple as looking at the id parameter that you pass in, and then constructing a new URL, in the form of a hyperlink, with the same URL, with the Id decremented and incremented by 1.
Gary
I don't think that that would be safe because, while there generally shouldn't be any gaps in the ID sequence, there might be. Even if you never delete a record, an error during an insert will mean that the current ID will not end up being used.
-
May 22nd, 2013, 08:07 AM
#5
Re: Navigating records next/previous
 Originally Posted by jmcilhinney
I don't think that that would be safe because, while there generally shouldn't be any gaps in the ID sequence, there might be. Even if you never delete a record, an error during an insert will mean that the current ID will not end up being used.
Ah, you are of course correct! 
Gary
-
May 22nd, 2013, 08:11 PM
#6
Re: Navigating records next/previous
 Originally Posted by jmcilhinney
Assuming that you have increasing numeric IDs, you can find the next record like this:
sql Code:
SELECT TOP 1 *
FROM MyTable
WHERE ID > @ID
and you pass the ID of the current record to the @ID parameter. The previous record is similar:
sql Code:
SELECT TOP 1 *
FROM MyTable
WHERE ID < @ID
ORDER BY ID DESC
This might work but it is not a common practice to fetch the next record one by one, usually you will have to use a pager or the paging capabilities of the formview. So you either either bring everything to the formview and select the current record according to the DataKeyNames id of formview(i only suggest that for small record sets and easy of use, lower of 100 records at least) of you must look for paging examples that will bring portions of data to your page.Select TOP 10 * or TOP 20 * etc might work somehow also if you modify JMC example(for the pager). Finally there is always the possibility of using a web service and bind your data with jquery but i don't think formview will work in that case.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 23rd, 2013, 02:13 AM
#7
Thread Starter
Registered User
Re: Navigating records next/previous
Dear all,
Thanks for all the suggestions. 
@gep13, the URL that was passed into Page B looks like this...card.aspx?mode=view&rec_num=war-2012-000041 <-- first 3 letters of the rec_num is abbreviation of a location; middle 4 digits is the year the record was created; and last 6 digits is running number for the entire year for that particular location.
My best guess will be to pass over the previous rec_num and next rec_num but it means that in the GridView, I will have to be able to retrieve the previous and next record and populate accordingly.
Anyone have any more idea?
-
May 23rd, 2013, 04:05 AM
#8
Re: Navigating records next/previous
Hey,
I am not sure that passing in additional information in the query string is the best approach.
I would suggest that John's approach is probably the best, unless you are looking to restructure the page, as suggested by sapator.
Based on the incoming URL, query your database for the next and previous article number, and construct URL's to place on the page.
Gary
-
May 27th, 2013, 11:36 PM
#9
Thread Starter
Registered User
Re: Navigating records next/previous
Hi Gary,
Understood... well let me think how it can be done... probably have to look into restructuring the page. >.<
Thank you and thanks all!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|