Wrox Programmer Forums
|
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
 
Old September 23rd, 2010, 09:00 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile Authorized reviews

Hello Imar,
For the last few days I was thinking to do something interesting with reviews.
As in the All.aspx page only authorized reviews are shown to users likewise how we can show only authorized reviews on the Default.aspx and AllByGenre.aspx page.

Secondly I want that users may post comments to reviews, for this I have created a new table ‘Comments’ with field ReviewId referring review, other fields include Id, Comment, CommentPoster, PostDate etc.
The thing I wanna show along with reviews and genres is no. of comments and name of last comment poster (CommentPoster).
For this I have added some fields in the Repeater as follows
Code:
      <h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name") %>'></asp:Literal></h3>
      <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# Eval("Reviews")%>'>
        <ItemTemplate>
          <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# "ViewDetails.aspx?ReviewId=" + Eval("Id").ToString() %>'>
          </asp:HyperLink><br />
          <asp:Label ID="Label1" runat="server"></asp:Label>
          Last Comment Posted By: <asp:Label ID="Label2" runat="server" Text='<%# Eval(CommentPoster) %>'></asp:Label> 
        </ItemTemplate>
      </asp:Repeater>
where text of Label1 should be total no. of posts and Label2 contains name of last poster.

Now the problem is that in code behind how I have the reference for the Comments table which may show the above mentioned fields.

Thank You in advance.
 
Old September 23rd, 2010, 09:16 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 Sophia,

Quote:
As in the All.aspx page only authorized reviews are shown to users likewise how we can show only authorized reviews on the Default.aspx and AllByGenre.aspx page.
Exactly the same way I did it; add a authorized == true statement to your where clause.

Quote:
I have the reference for the Comments table
Since you haven't provided any details, I can't recommend a working solution, It all depends on how you implemented things. As an example, here's a quick LINQ query that selects all Albums and a count of the number of Pictures they contain:
Code:
 
 
var albums = from a in myDataContext.PhotoAlbums     
             select new {Album = a, NumberOfPictures = a.Pictures.Count()};
It should be possible to do something similar with the Comments....

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 September 24th, 2010, 07:03 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Thanks Imar, I will do the same.
 
Old September 26th, 2010, 08:51 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hello Imar,
Greetings!!
It has not been so easy getting authorized reviews.
The code behind file has the following query on Default.aspx page

Code:
Dim favGenres = From genre In myDatabaseContext.Genres _
                    Order By genre.Name _
                    Where Profile.FavoriteGenres.Contains(genre.Id) _
                    Select New With {genre.Name, genre.Reviews}
Here how we can get the authorized property set to true?
Please specify the code as I can not access authorized property in the code above.

Secondly, clearly as we do not have any property NumberOfPictures in our data context so when ever I try to show no. of pictures as follows
Code:
code behind:
Dim Albums = From a in myDataContext.PhotoAlbums     
             Select New With {Album = a, .NumberOfPictures = a.Pictures.Count()}

aspx page:
<asp:Literal ID="Literal2" runat="server" Text='<%# Eval("NumberOfPictures") %>' />
then it shows the following error message.
'PhotoAlbum' does not contain a property with the name 'NumberOfPictures'.
So how the new (custom) property value should be displayed?

Thank you.
 
Old September 26th, 2010, 09:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You could add a Where clause on the Reviews collection in the Select statement. Something like this should work:

Code:
 
Select New With {genre.Name, .Reviews = genre.Reviews.Where(Function(item) item.Authorized = True)}
With regard to the second question: I guess it depends on your setup. The count is available for each item, so if your label is placed in, say, a Repeater it should work.

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!
 
Old September 26th, 2010, 09:27 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Thanks,
I will try the same code, but again I have some doubts regarding second question that what is the method of displaying custom properties?

Thank You Imar.
 
Old September 26th, 2010, 11:48 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,

I don't understand what you're asking....

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 September 30th, 2010, 08:05 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Hello Imar,
Thanks, first method really worked, now I get only authorized reviews even on Default.aspx page.

But my second question is that I have 3 tables
Genre, Review both same as in book and
Comments which has Id(Primary key), Message, ReviewId (foreign key with Id in Review table), Owner.

The source view for the page is
Code:
<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
      <h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name") %>'></asp:Literal></h3>
      <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# Eval("Reviews")%>'>
        <ItemTemplate>
          <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# "ViewDetails.aspx?ReviewId=" + Eval("Id").ToString() %>'>
          </asp:HyperLink><br />
          <asp:Label ID="Label1" runat="server" Text='<%# Eval("NoComment") %>' ></asp:Label>
         
        </ItemTemplate>
      </asp:Repeater>
    </ItemTemplate>
  </asp:Repeater>
Code:
Dim favGenres = From genre In myDatabaseContext.Genres _
                    Order By genre.Name _
                    Where Profile.FavoriteGenres.Contains(genre.Id) _
                    Select New With {genre.Name, genre.Reviews}

Repeater1.DataSource = favGenres
Repeater1.DataBind()
If I try to use anonymous property .NoComment here in Select clause then an error is generated as follows.
'Review' does not contain a property with the name 'NoComment'.
So how I assign value to property NoConnent in code behind that is how to modify it so that it shows no of comments in correspondent review.
 
Old September 30th, 2010, 08:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
If I try to use anonymous property .NoComment here in Select clause then an error is generated as follows
I don't see a NoComment item in your select clause so it makes sense that you get an error...

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 1st, 2010, 09:12 AM
Friend of Wrox
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Yes I know I did not mention that element this time as I had mentioned it already. Anyways code behind file has the following code snippet
Code:
Dim favGenres = From genre In myDatabaseContext.Genres, _
                    r in myDatabaseContext.Reviews Order By genre.Name _
                    Where Profile.FavoriteGenres.Contains(genre.Id) _
                    Select New With {genre.Name, genre.Reviews _
                    .NoComment = r.Comments.Where(Function(item) item.ReviewId = r.Id).Count() }

Repeater1.DataSource = favGenres
Repeater1.DataBind()
And source view is
Code:
<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
      <h3><asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Name") %>'></asp:Literal></h3>
      <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# Eval("Reviews")%>'>
        <ItemTemplate>
          <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# "ViewDetails.aspx?ReviewId=" + Eval("Id").ToString() %>'>
          </asp:HyperLink><br />
          <asp:Label ID="Label1" runat="server" Text='<%# Eval("NoComment") %>' ></asp:Label>
         
        </ItemTemplate>
      </asp:Repeater>
    </ItemTemplate>
  </asp:Repeater>
I still get the error
'Review' does not contain a property with the name 'NoComment'.
What may be the solution.
Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4:Displaying the reviews p.126-128 drgnhiker BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 6 November 6th, 2010 04:04 AM
Reviews jack_hilary BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 10 May 23rd, 2010 03:55 PM
problems with the reviews table in chapter 4 derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 15th, 2007 03:58 AM
Un authorized Exception ashokparchuri ASP.NET 1.x and 2.0 Application Design 7 December 12th, 2006 03:23 AM
I've read some bad reviews; what do readers think? disruptivehair BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 11 January 18th, 2006 04:44 PM





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