Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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 October 4th, 2016, 02:11 PM
Authorized User
 
Join Date: Dec 2015
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default Linking Reviews to ViewDetails Form

Does anyone have any suggestions on how one might link the individual Reviews in the "BulletedList" of the "AllByGenre" Form with the "ViewDetails" Form. I've tried a number of approaches but can not seem to find a way to pass the "ReviewId" to the url for the ViewDetails.aspx. For example, something like the following:

<asp:BulletedList ID="ReviewList" runat="server" DisplayMode="LinkButton"
DataSource = '<%# Eval("Reviews") %>' DataTextField="Title" DataValueField="Id"
NavigateUrl='<%# "ViewDetails?ReviewId=" + Reviews.Id.ToString()%>'>

gives the following error:Reviews does not exist in current context.

or alternatively something like the following:

<asp:BulletedList ID="ReviewList" runat="server" DisplayMode="LinkButton" DataSource = '<%# Eval("Reviews") %>' DataTextField="Title" DataValueField="Id" NavigateUrl='<%# "ViewDetails?ReviewId=" + Eval("Id")%>'>

gives the following error message: System.Web.HttpException: DataBinding: does not contain a property with the name 'Id'.

Any suggestions would be greatly appreciated.

T.
 
Old October 5th, 2016, 03:36 AM
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,

Can you provide your full code including code behind? Is your database scheme exactly the same as in the book?

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 October 5th, 2016, 12:34 PM
Authorized User
 
Join Date: Dec 2015
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default Linking Reviews to ViewDetails Form

Imar:

My code is given below. It’s pretty much the same as in the book with the exception that I’ve changed some names: Reviews = Songs, Genre = Bands and PlanetWroxEntities becomes TRTDevelopmentSongsAndBandsEntities. I know what I’m asking extends what is presented in the book but as I looked at my web site I felt it really needed to have functionality equivalent to that seen in the “All.aspx” and “My Favorite Reviews” pages. However, after several days and a lot of "Googling" I have simply not been able to implement that functionality. I don’t even know if I’m on the right tract.

For the present I have implemented a solution on my web site that I hate. I’ve inserted a second bulleted list underneath that of in the “AllSongsByBand.aspx” form using the “DataDisplayMode = “HyperLink” and ‘DataTextField =”ClipLink”’ (a filed I've inserted into the "Songs" table that provides a url link to a clip of the song). This works to an extent but does not link the “ViewDetail” Form, looks awful, and is not acceptable.

The “ViewDetails.aspx” and “ViewDetails.aspx.cs” look pretty much the same as in the book with the exception that I’ve changed names (“Songs” and “Bands” again) and added a couple of additional fields to display. If you need to look at the code I can send it.

I appreciate your rapid response. Any guidance or pointers or even an opinion as to whether or not I’m on the right tract would be greatly appreciated.

I'm greatly indebted to you as this is my first real attempt a creating a web site. My site does work perfectly anologus to that you have created in the book and with the knowledge you provided have been able to make some adaptations. I still have a lot nore to learn, however, about how Asp.Net works :-)

Thanks
Code:
<%@ Page Title="All Songs By A Band" Language="C#" MasterPageFile="~/MasterPages/Frontend.master"
  AutoEventWireup="true" CodeFile="AllSongsByBand.aspx.cs" Inherits="Songs_AllSongsByBand" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
  <asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
      <h3>
        <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Band1")
 %>'></asp:Literal>
      </h3>
      <asp:BulletedList ID="SongList" runat="server" 
    DataSource='<%# Eval ("Songs") %>' DataTextField="Title" 
    DisplayMode="Text">
      </asp:BulletedList>
    </Itemtemplate>
  </asp:Repeater>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cpClientScript" runat="Server">
</asp:Content>
And the “Code Behind”
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Songs_AllSongsByBand : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
      using (TRTDevelopmentSongsAndBandsEntities MyEntities = new
TRTDevelopmentSongsAndBandsEntities())
      {
        var AllBands = from Band in MyEntities.Bands.Include("Songs")
                       orderby Band.Band1
                       select new { Band.Band1, Band.Songs};
        Repeater1.DataSource = AllBands.ToList();
        Repeater1.DataBind();
      }
    }
  }
 
Old October 6th, 2016, 05:59 PM
Authorized User
 
Join Date: Dec 2015
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Default Solved

Ok, after about three weeks of frustration, the answer was already there in the project. Essential I got rid of the "BulletedList" (I did need a whole new approach). I then used the code that was already present in the "Default" form of the "Reviews" folder: This is the code that lists the favorite genre from the "myProfile" list. so the code in the "AllReviewsByGenre" form looks like this:

Code:
 <asp:Repeater ID="BandRepeater" runat="server">
    <HeaderTemplate>
      <p>Below you will find a list of songs for each of your favorite bands.</p>
    </HeaderTemplate>
    <ItemTemplate>
      <h3>
        <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Band1") %>'></asp:Literal>
      </h3>
      <h4>
        <asp:Literal ID="Literal2" runat="server" Text='<%# Eval("Notes") %>'></asp:Literal>
      </h4>
        <asp:Repeater ID="SongRepeater" runat="server" ItemType="Song" DataSource='<%# Eval("Songs") %>'>
          <ItemTemplate>
            <asp:HyperLink ID="HyperLink1" CssClass="HyperLinkBullet" runat="server" Text='<%# Item.Title %>'
              NavigateUrl='<%# "ViewDetails?SongId=" + Item.Id.ToString() %>'>
            </asp:HyperLink><br />
          </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
  </asp:Repeater>
[NB: remember I have replaced "Genre with "Bands" and "Reviews" with "Songs"]

I've added a CssClass to the Hyperlink and added the following styling for that class:

Code:
.HyperLinkBullet

{
    display: list-item;
    list-style-type: disc;
    margin-top: 10px
}
The code behind is essentially the same as that in "Default.aspx.cs" in the Songs folder.

The solution works well and actually provides more flexability in styling the bullet types.

Hopefully this may help any others wishing to modify a "BulletedList" styling. Anyone wishing to see the result can go to TRTDevelopment.com :-)

T.
 
Old October 8th, 2016, 07:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, I was going to suggest the same thing; just didn't have the time to post earlier.

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
Label with multiple lines in ViewDetails page sophia BOOK: Beginning ASP.NET 4 : in C# and VB 1 August 20th, 2012 02:11 PM
Chapter 4: Pages 130 - 132 Querying for reviews & Displaying the reviews FlaUsa BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 January 24th, 2012 01:55 AM
Need Code For Form Linking In VC++ ElectricBlue Visual Studio 2005 0 March 18th, 2009 03:16 PM
Linking a query to a form hikinfool Access 3 February 24th, 2006 06:09 PM
linking form linh Access 3 February 9th, 2006 09:26 AM





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