 |
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
|
|
|
|
|

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

September 23rd, 2010, 09:16 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

September 24th, 2010, 07:03 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
|
|
Thanks Imar, I will do the same.
|
|

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

September 26th, 2010, 09:20 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

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

September 26th, 2010, 11:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I don't understand what you're asking....
Imar
|
|

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

September 30th, 2010, 08:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

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