Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
  #11 (permalink)  
Old July 26th, 2012, 10:55 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I opened NewAlbum.aspx and added test album and use picture from your resources, and when ManagePhotoAlbums page was loaded I had only one item, the one I've entered now during this session with no sign for other previous 3. Thanks, Alex
If I interpret this correctly, then this is by design. NewAlbum.aspx does what its name implies: it creates a new album. So when you create a new album and then go to ManageAlbum, the pictures you see there are just the ones you add to that album. So, on the first request, you won't see any pictures at all. If you then upload one, you should only see that image.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #12 (permalink)  
Old July 26th, 2012, 01:09 PM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ok, what do I have to do in order to see all albums stored in database with corresponded pictures?
  #13 (permalink)  
Old July 26th, 2012, 01:14 PM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Your picture on page 518 figure 14-17 shows all the albums, mine only one with PhotoAlbumID defined in query string
  #14 (permalink)  
Old July 26th, 2012, 01:21 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> Your picture on page 518 figure 14-17 shows all the albums

It does not; it shows a single album (PhotoAlbumId=3) that has *multiple pictures*. Simply add more pictures to the album using the FileUpload control and they should show up (they did on my screen, with your code).

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #15 (permalink)  
Old July 26th, 2012, 01:45 PM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you, somehow I thought it shows all the rest of the albums with pictures, my fault
  #16 (permalink)  
Old July 27th, 2012, 08:13 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Nope, not when editing.

When you want to *display* all albums and pictures on a single page, you can use a nested Repeater or other data control as explained in the book. Here's a quick example (using VB, but I hope you get the idea):

AllAlbums.aspx
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AllAlbums.aspx.vb" Inherits="AllAlbums" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <h1>All Albums</h1>
    <asp:Repeater ID="AllAlbums" runat="server">
      <ItemTemplate>
        <h2>
          <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name")%>'></asp:Literal></h2>
        <asp:Repeater ID="Pictures" runat="server" DataSource='<%# Eval("Pictures")%>'>
          <ItemTemplate>
            <h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Description")%>'></asp:Literal></h3>
            <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageUrl")%>' />
          </ItemTemplate>
        </asp:Repeater>
      </ItemTemplate>
    </asp:Repeater>
  </div>
  </form>
</body>
</html>
And the code behind:

AllAlbums.aspx.vb
Code:
 
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Using db As New PlanetWroxModel.PlanetWroxEntities
  AllAlbums.DataSource = db.PhotoAlbums.Include("Pictures").Where(Function(x) x.Pictures.Any())
  AllAlbums.DataBind()
End Using
End Sub
This code gets all the albums and pictures (using Include("Pictures", so they are retrieved on the first sql statement and not separately for each album). I am using Any() to only retrieve albums that have at least one picture.

The markup then has a nested repeater that displays the pictures it gets from the outer repeater using Eval("Pictures"). I am just displaying the name, description and ImageUrl, but obviously you can modify the HTML to your liking.

The concepts used in this sample are all explained throughout the book, but let me know if you need any clarification.

Note: editing all albums at once is a lot more complex as you need to keep track of which album you're editing.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch.14 first try it out lrk89 BOOK: Beginning ASP.NET 4 : in C# and VB 7 February 10th, 2014 05:12 PM
ch: 14, Try it out pg: 515 binaryspirit BOOK: Beginning ASP.NET 4 : in C# and VB 6 May 4th, 2012 12:49 PM
Ch.14 - First try it out jxFive BOOK: Beginning ASP.NET 4 : in C# and VB 3 November 3rd, 2011 03:55 PM
Chp 14, PhotoAlbum extension nanonerd BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 29th, 2011 11:46 AM
Ch 14 Help digink BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 November 3rd, 2009 03:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.