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

January 20th, 2012, 11:45 AM
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
Chapter 13 exercise
Hi, im doing the exercise on pages 498-502 in chapter 13. In the exercise you create a page called AddEditReview.aspx, add a DetailsView to it and set it up so you can insert new records.
It says in the exercise that after you insert a new Review, you should be able to go on Manage Reviews, then select a Genre which will give you a list of Reviews for that Genre.
After that you should be able to click on a Review which should open up AddEditReview.aspx so your able to edit the review. For some reason this page comes up blank with only 3 links showing and no details view. Not sure why. Seems strange because i insert the new review using AddReviewEdit.aspx but when it opens for the second time the DetailsView doesent show.
Any help would be appreciated.
|

January 20th, 2012, 11:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Can you post the code for the relevant pages or make your site's source available as a ZIP somewhere?
Imar
|

January 20th, 2012, 12:15 PM
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
Thanks for the reply Imar, here is the source code for my AddEditReview.aspx page
Code:
<%@ Page Title="Planet Wrox - Management - Insert and Update Reviews" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="AddEditReview.aspx.cs" Inherits="Management_AddEditReview" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<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="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Summary" HeaderText="Summary"
SortExpression="Summary" />
<asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
<asp:BoundField DataField="GenreId" HeaderText="GenreId"
SortExpression="GenreId" />
<asp:CheckBoxField DataField="Authorized" HeaderText="Authorized"
SortExpression="Authorized" />
<asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime"
SortExpression="UpdateDateTime" />
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
DeleteCommand="DELETE FROM [Review] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [Review] ([Title], [Summary], [Body], [GenreId], [Authorized], [UpdateDateTime]) VALUES (@Title, @Summary, @Body, @GenreId, @Authorized, @UpdateDateTime)"
SelectCommand="SELECT [Id], [Title], [Summary], [Body], [GenreId], [Authorized], [UpdateDateTime] FROM [Review] WHERE ([Id] = @Id)"
UpdateCommand="UPDATE [Review] SET [Title] = @Title, [Summary] = @Summary, [Body] = @Body, [GenreId] = @GenreId, [Authorized] = @Authorized, [UpdateDateTime] = @UpdateDateTime WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Summary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="GenreId" Type="Int32" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="UpdateDateTime" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Summary" Type="String" />
<asp:Parameter Name="Body" Type="String" />
<asp:Parameter Name="GenreId" Type="Int32" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="UpdateDateTime" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
The only other code that has been inserted is the quick if satement in the pages load function.
Thanks Imar,
Nick
|

January 20th, 2012, 12:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you also post the code for the List page? I am guessing that the ID is not passed correctly through the query string.
Cheers,
Imar
|

January 20th, 2012, 12:47 PM
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
Sorry Imar, when you say the List page do you mean the Reviews.aspx ?
Thanks,
Nick
|

January 20th, 2012, 01:37 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, sorry, that's the page I mean (it shows a list of reviews.... ;-) )
Cheers,
Imar
|

January 20th, 2012, 01:47 PM
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
Yeah ill post it now, just didnt want to post the code for the wrong page :) !
Code:
<%@ Page Title="Planet Wrox - Management - Reviews" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Reviews.aspx.cs" Inherits="Management_Reviews" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Name"
DataValueField="Id">
<asp:ListItem Value="">Make a selection</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource2">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="AddEditReview.aspx?Id=0" DataTextField="Title"
Text="Title" />
<asp:TemplateField HeaderText="Authorized" SortExpression="Authorized">
<ItemTemplate>
<asp:Label ID="AuthorizedLabel" runat="server" Text='<%# GetBooleanText(Eval("Authorized")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CreateDateTime" DataFormatString="{0:g}"
HeaderText="CreateDateTime" SortExpression="CreateDateTime" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<a href="AddEditReview.aspx">Insert New Review</a><asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
DeleteCommand="DELETE FROM [Review] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [Review] ([Title], [Authorized], [CreateDateTime]) VALUES (@Title, @Authorized, @CreateDateTime)"
SelectCommand="SELECT [Title], [Id], [Authorized], [CreateDateTime] FROM [Review] WHERE ([GenreId] = @GenreId)"
UpdateCommand="UPDATE [Review] SET [Title] = @Title, [Authorized] = @Authorized, [CreateDateTime] = @CreateDateTime WHERE [Id] = @Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="GenreId"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="CreateDateTime" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]">
</asp:SqlDataSource>
</asp:Content>
Thanks Imar,
Nick
|

January 20th, 2012, 02:09 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Ah, there we have it:
Code:
<asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="AddEditReview.aspx?Id=0" DataTextField="Title" Text="Title" />
You're always passing 0 as the ID (which doesn't exist in the database). Change 0 to {0} to have {0} replaced with the value in the DataNavigateUrlFields field:
DataNavigateUrlFormatString="AddEditReview.aspx?Id ={0}"
Hope this helps,
Imar
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

January 20th, 2012, 02:13 PM
|
Authorized User
|
|
Join Date: Dec 2011
Posts: 43
Thanks: 11
Thanked 0 Times in 0 Posts
|
|
Yes it works now!
Rookie error but it makes sense now!
Thanks again for that Imar,
Nick
|
Similar Threads
|
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
Chapter ! - Exercise 4 |
tinmegali |
BOOK: Beginning Flash, Flex, and AIR Development for Mobile Devices |
0 |
November 25th, 2011 09:18 PM |
Chapter 8 exercise 3 |
Will |
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 |
8 |
March 4th, 2010 04:15 AM |
Chapter 8 exercise 1 |
Will |
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 |
2 |
March 2nd, 2010 03:26 PM |
Chapter 13 Exercise 3 solution |
firblazer |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
3 |
April 19th, 2008 07:16 AM |
chapter 3 exercise 4 |
walkamongus |
BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 |
0 |
September 10th, 2007 09:34 PM |
|
 |
|