 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
 | This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

October 12th, 2009, 07:01 PM
|
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 16
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Querry string passing 2 values
Hi Imar
I have just finished Chapter 13 and have added the option for the user to click on a hyperlink and see a larger version of an image on a new page. This is done by using a querry string.
I was wondering how if it was possiable to alow the user to navigate through the photo album on the page with the large image. So there would be on the large image page and press next or prev and a new large image would be displayed etc etc.
I m guessing I woul need to pass two values PhotoAlbumID and PictureID to laod the correct image. The large image is currently in a list view so I could enable the next/prev buttons to navigate to the next image and would there need some code i.e. +1 to the PictureID.
Is this possiable or maybe a simplier way to do this? Sorry if this does not make sense its rather late were I m from yawn lol
Thanks in advance
Hippo
|
|

October 12th, 2009, 08:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
I have never seen the book and have no idea what the code looks like, but...
Unless a given PictureID can appear in more than one album, there should be no reason to pass both values. You could use SQL to find the album that the given PictureID belongs to.
I'm a little bothered by your assumption that moving to the next picture just means adding 1 to the current PictureID. What happens if some pictures have been removed, and you have "holes" in the ID numbering???
|
|

October 13th, 2009, 03:26 AM
|
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 16
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks for the help, in regards to moving to the next photo I was thinking in arrays as there is no gaps in information instead of a table thanks for pionting this out.
Regards
Hippo
|
|

October 13th, 2009, 05:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I haven't actually tried it myself but maybe you can do something like this:
Code:
using (PlanetWroxDataContext myDatabaseContext = new PlanetWroxDataContext())
{
int pictureId = Convert.ToInt32(Request.QueryString["PictureId"]);
int albumId = Convert.ToInt32(Request.QueryString["AlbumId"]);
var next = (from p in myDatabaseContext.Pictures
where p.PhotoAlbumId == albumId && p.Id > pictureId
orderby p.Id ascending
select p.Id).FirstOrDefault();
if (next != 0)
{
// next contains the ID of the next picture
}
}
This gets the AlbumId and PictureId from the query string. As OP pointed out, you don't necessarily need AlbumId but in this case it makes things a little easier and quicker to implement. Then with these two IDs you can query the next PictureId from the database. It's done by querying the pictures from the database with an identical AlbumId but with an own ID larger than the current one, sorted by the ID. FirstOrDefault then gets the first item, or the default value for an int (zero) when there are no more pictures.
Hope this works / helps. If not, please let me know....
Imar
|
|

October 13th, 2009, 07:47 AM
|
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 16
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
Thanks for the info.
Just for a few questions: -
Would I be correct in saying the c# code sit in the page load event of the page that displays the large image.
Also would the photoalbumID & picture ID be passed from the querry string into the c# code.
Finally would I assign the variable next to a command button which would trigger the next image to be displayed when pressed
Thanks in advance
Hippo
|
|

October 13th, 2009, 08:04 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, Yes, and Possibly.
Instead of a Command Button you can also create a HyperlInk:
myHyperLink.NavigateUrl = string.Format("Details.aspx?PictureId={0}", next);
This creates a link like Details.aspx?PictureId=234
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

October 13th, 2009, 08:34 AM
|
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 16
Thanks: 8
Thanked 0 Times in 0 Posts
|
|
Hi Imar
Thanks for your help, will start on getting ur code working tonight
On last question when passing two values through a querry string
Would I just do something like
"Details.aspx?PhotoAlbum={0}&&PictureId={0} "
Sorry for all these dumb ass questions
Regards
Hippo
|
|

October 13th, 2009, 08:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Almost. You only need a single &:
"Details.aspx?PhotoAlbum={0}&PictureId={1}"
Notice how I changed the second {0} to {1}. String.Format uses 0 based indexers, so {0} refers to the first item you're passing to it, and {1} as the second.
You need need to use this string in a String.Format call:
string url = String.Format("Details.aspx?PhotoAlbum={0}&Picture Id={1}", albumId, pictureId);
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|
 |