Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Beginning ASP.NET 4.5 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : 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
 
Old March 12th, 2014, 06:36 PM
Authorized User
 
Join Date: Mar 2014
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chap 14&15 - Combining AllByGenre.aspx and All.aspx

Hi Imar,
First of all thank you for this amazing book.

I'm working on my own project now and I'm trying to include the All.aspx page inside AllByGenre.aspx page.

AllByGenres.aspx shows all genres with DisplayMode="Text". Here I changed DisplayMode to "HyperLink" where on browser all reviews are shown as links:

Code:
<asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <h3><asp:Literal ID="Literal1" runat="server" Text='<%#   Eval("Name") %>'></asp:Literal></h3>
            <asp:BulletedList ID="ReviewList" runat="server" DataSource='<%# Eval("Reviews") %>' DataTextField="Title" DisplayMode="HyperLink"></asp:BulletedList>
        </ItemTemplate>
        
    </asp:Repeater>
Now when I click a review I want to go to the ViewDetails.aspx page and show me the details of that review (Title, Summary and Body):

Code:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "ViewDetails.aspx?ReviewId=" + Item.Id.ToString() %>' Text='<%# Item.Title%>'></asp:HyperLink>
I tried putting the HyperLink of the All.aspx inside AllByGenres.aspx but is showing something like this:

Code:
System.InvalidCastException: Unable to cast object of type '<>f__AnonymousType0`2[
In AllByGenres.aspx I created another repeater with that HyperLink inside, below the first repeater, but now is showing 'All Reviews' below the 'All Reviews Grouped by Genre'.

Thanks.
 
Old March 16th, 2014, 12:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

When setting DisplayMode to HyperLink, you need to set the Value property to the URL you want to link to: http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx

Furthermore, the inner control has a collection of anonymous objects assigned to it, so you need use Eval rather than the strongly bind Item property. E.g. something like this:

Value='<%# "ViewDetails.aspx?Id=" + Eval("Id")' ..../>

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!
 
Old March 26th, 2014, 02:40 PM
Authorized User
 
Join Date: Mar 2014
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for help Imar!
The answer was on Reviews/All.aspx http://aspnet45.planetwrox.com/Reviews/All.aspx

I have another question: How can I display Images instead HyperLinks?
For example, display an clickable image for the review: Sonic Youth: Daydream Nation live in Roundhouse, London, instead asp:Hyperlink.

I tried like this:
Code:
<asp:HyperLink ID="HyperLink1" ImageUrl="~/Images/image_Sonic Youth.jpg" runat="server" Text='<%# Item.Title%>' NavigateUrl='<%# "ViewDetails.aspx?ReviewId=" + Item.Id.ToString() %>'></asp:HyperLink>
But now all reviews gets the same image. How can I give each review different image? How to know which image to use? It can be some connection between image name and review?

Thanks.

Last edited by southside123; March 26th, 2014 at 03:18 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 - All.aspx error Dbug BOOK: Beginning ASP.NET 4.5 : in C# and VB 6 September 18th, 2013 09:13 AM
ch 14: AllByGenre.aspx.cs binaryspirit BOOK: Beginning ASP.NET 4 : in C# and VB 6 May 4th, 2012 09:08 AM
Imar: Chp 14 - ManagePhotoAlbum.aspx nanonerd BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 13th, 2011 12:38 PM
Chap. 7 Multiple Default.aspx pages Wrong Planet BOOK: Beginning ASP.NET 4 : in C# and VB 3 August 25th, 2011 05:57 PM





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