Wrox Programmer Forums
|
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
 
Old July 25th, 2010, 09:06 PM
Authorized User
 
Join Date: Jun 2010
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Management Sortation Question

How do you get the Management Section to sort correctly. I tried adjusting the sort order and does not work. the Genres sorts ok. But the reviews does not sort. Any suggestions?

Thanks Larry

code

<%@ Page Title="SCS Technology Consultants - Management - Genres" Language="VB" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="false" CodeFile="Genres.aspx.vb" Inherits="Management_Genres" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
<asp:Label ID="ErrorMessage" runat="server" CssClass="ErrorMessage" EnableViewState="False"></asp:Label>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display." CellPadding="4" ForeColor="#333333" GridLines="None">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
&nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
&nbsp;<asp:LinkButton ID="DeleteLink" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="200px" DataField="Name" HeaderText="Name" SortExpression="Name">
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" DeleteCommand="DELETE FROM [Genre] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Genre] ([Name], [SortOrder]) VALUES (@Name, @SortOrder)" ProviderName="<%$ ConnectionStrings:PlanetWroxConnectionString1.Prov iderName %>" SelectCommand="SELECT Genre.Id, Genre.Name, Genre.SortOrder, COUNT(Review.Id) AS NumberOfReviews FROM Genre LEFT OUTER JOIN Review ON Genre.Id = Review.GenreId GROUP BY Genre.Id, Genre.Name, Genre.SortOrder" UpdateCommand="UPDATE [Genre] SET [Name] = @Name, [SortOrder] = @SortOrder WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="SortOrder" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="SortOrder" Type="Int32" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<script type="text/javascript">
$(function ()
{
$('.GridView tr:odd:not(.GridViewPagerStyle)').addClass('GridVi ewAlternatingRowStyle');
});
</script>
</asp:Content>

/code
 
Old July 26th, 2010, 04:03 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 Larry,

Can you define "does not work"? What is the problem exactly? Do you get an error? If so, which one?

And what are you trying to accomplish? A one-time sort whe displaying the items, or a sortable Grid? And how is the code below related to this? It's from the Genres, right? Are you trying to modify that code, or is it just for reference?

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 July 26th, 2010, 03:05 PM
Authorized User
 
Join Date: Jun 2010
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Management Sortation Question

Go into the management section for Genres and change the sort order. Display the Genres webpage and it sorts ok.
Now go into the All reviews webpage and the sort order does not change.
So the All reviews webpage does not reflect the sort order from the Genres webpage. Should not be the same sort order?

Larry
 
Old July 26th, 2010, 03:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am still not completely with you...

How do you change the sort order? By clicking the SortOrder heading? If so, that doesn't update the datatabase; it's purely a presentational sort that just updates the current screen. You need to edit a genre, change the number for the SortOrder and apply the changes.

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!

Last edited by Imar; July 26th, 2010 at 04:52 PM..
 
Old July 26th, 2010, 04:00 PM
Authorized User
 
Join Date: Jun 2010
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Management Sortation Question

I am editing a genre, change the number for the SortOrder and applying the changes.
This change is reflected in the Genre Webpage, but not the all reviews page.

Larry
 
Old July 26th, 2010, 04:50 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In the management page for the Reviews? That works for me.

Can you please be more specific? This may be easy to solve, but without exact steps it's pretty hard to figure out what you mean.

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 July 26th, 2010, 06:18 PM
Authorized User
 
Join Date: Jun 2010
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Management Sortation Question

Step1: Cllick on the Default.aspx in of the website which brings the home page. Logon in and the

Bring up the Default.aspx in Management section.

Click on Manage Genres page.

Click on edit on the one of the Genres.

Change the sort order and update.

Bring up the Home page.

Click on the AllByGenre.aspx

Review the Genres items they are correct order.

Then click on the Reviews/All.aspx page.

Review the Reviews/All.aspx page.

The sort order does not match the AllByGenre.aspx page.


Comment: The sorts should match?

Larry
 
Old July 26th, 2010, 06:27 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 Larry,

Ah, now you're being specific.... ;-)

This is not a bug; it's by design. Take a look at the code you added the code behind of the All page:

Code:
 
 var allReviews = from review in myEntities.Reviews
                       where review.Authorized == true
                       orderby review.CreateDateTime descending
                       select review;
The reviews are being sorted explicitly by their creation date, not by their sort order.

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 July 26th, 2010, 07:56 PM
Authorized User
 
Join Date: Jun 2010
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Management Sortation Question

Thanks Imar, I am learning. Look what I did. Getting Good.
It's now sorting the way I like it.

Larry

code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using myEntities As New PlanetWroxEntities()
Dim allReviews = From review In myEntities.Reviews
Where review.Authorized = True
Order By review.Title Ascending
Select review
Repeater1.DataSource = allReviews
Repeater1.DataBind()
End Using
End Sub

/code
 
Old July 27th, 2010, 02:57 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Excellent.

And if you want to do what you initially wanted to do (sort on the SortOrder) you can "dot" into the Genre and its ID like this:

Code:
Dim allReviews = From review In myEntities.Reviews
                 Where review.Authorized = True
                 Order By review.Genre.SortOrder
                 Select review
I left out ascending as it's optional (and the default).

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
Chapter 15 Role Management Question will.wei BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 April 9th, 2009 02:17 AM
roles and management MunishBhatia ASP.NET 2.0 Professional 2 November 3rd, 2007 01:01 AM
FileUpload Memory Management Question dparsons ASP.NET 2.0 Professional 0 February 21st, 2007 10:22 AM
EMAIL MANAGEMENT [email protected] ASP.NET 2.0 Basics 0 July 7th, 2006 04:48 AM
state management nalla ASP.NET 1.0 and 1.1 Professional 2 December 21st, 2005 01:19 AM





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