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

January 21st, 2010, 01:02 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 12 last try it out p413
yo imar!
awesome book! with my personal mission of not sleeping before i finish the try it out, looks like i'm stomped on this one. (lack of errors i guess) basically the db is not updating. (new entry doesn't show up in the manage reviews) what do you think would be the best way to display if a new review has been entered correctly. (something like the sent message in the email chapter) anyways, here's my code. thanks in advance!
Code:
<%@ Page Language="C#" MasterPageFile="~/MasterPages/ManagementMaster.master" AutoEventWireup="true" CodeFile="AddEditReview.aspx.cs" Inherits="Management_AddEditReview" Title="Management - Insert and Update Reviews" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert"
Height="50px" Width="125px" oniteminserted="DetailsView1_ItemInserted"
oniteminserting="DetailsView1_ItemInserting"
onitemupdated="DetailsView1_ItemUpdated"
onitemupdating="DetailsView1_ItemUpdating"
AllowPaging="True" >
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
ReadOnly="True" SortExpression="Id" />
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter a Title" Text="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please enter a Title" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Summary" SortExpression="Summary">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Summary") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="500" Height="100" Text='<%# Bind("Summary") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please enter a summary" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Width="500" Height="100" Text='<%# Bind("Summary") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Pleaes enter a Summary" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Body" SortExpression="Body">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Width="500" Height="100" Text='<%# Bind("Body") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Enter the Body" ControlToValidate="TextBox3"></asp:RequiredFieldValidator>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" Width="500" Height="100" Text='<%# Bind("Body") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Enter the Body" ControlToValidate="TextBox3"></asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GenreId" SortExpression="GenreId">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("GenreId") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sdsGenres"
DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GenreId") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sdsGenres"
DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GenreId") %>'>
</asp:DropDownList>
</InsertItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime"
SortExpression="UpdateDateTime" Visible="False" />
<asp:CheckBoxField DataField="Authorized" HeaderText="Authorized"
SortExpression="Authorized" />
<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], [UpdateDateTime], [Authorized]) VALUES (@Title, @Summary, @Body, @GenreId, @UpdateDateTime, @Authorized)"
SelectCommand="SELECT [Id], [Title], [Summary], [Body], [GenreId], [UpdateDateTime], [Authorized] FROM [Review] WHERE ([Id] = @Id)"
UpdateCommand="UPDATE [Review] SET [Title] = @Title, [Summary] = @Summary, [Body] = @Body, [GenreId] = @GenreId, [UpdateDateTime] = @UpdateDateTime, [Authorized] = @Authorized WHERE [Id] = @Id">
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<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 DbType="Date" Name="UpdateDateTime" />
<asp:Parameter Name="Authorized" Type="Boolean" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
<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 DbType="Date" Name="UpdateDateTime" />
<asp:Parameter Name="Authorized" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsGenres" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]">
</asp:SqlDataSource>
</asp:Content>
Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Management_AddEditReview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.Get("Id") != null)
{ DetailsView1.DefaultMode = DetailsViewMode.Edit; }
}
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
EndEditing();
}
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
e.Values["UpdateDateTime"] = DateTime.Now;
}
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
EndEditing();
}
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
e.NewValues["UpdateDateTime"] = DateTime.Now;
}
private void EndEditing()
{
Response.Redirect("Reviews.aspx");
}
}
|
|

January 21st, 2010, 01:04 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
oh i forgot to mention. i checked in the db itself and it doesn't show up there as well. a problem with the insert function perhaps?
|
|

January 21st, 2010, 01:41 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yo???? Have we meet before? I don't think so....
Anyway, you need to provide more information. This is too much code, and too little explanation.
What happens when you debug the pages in the Code Behind by setting a breakpoint and hitting F5? (Or refer to chapter 17 for more details).
Did you compare your source with mine?
Imar
|
|

January 21st, 2010, 08:02 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sorry, just trying to be informal.
will check chapter 17 and be back and see. hope I find it on my own :)
Thanks Imar!
|
|

January 21st, 2010, 08:21 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks for the tip imar! (i forgot that you had all the code)
apparently the difference is this
Code:
<asp:Parameter DbType="Date" Name="UpdateDateTime" />
my UpdateDateTime, instead of having type, had the DbType. where do you think I made a mistake? In defining the dataview perhaps?
thanks in advance! Taking notes so that I can prevent the same mistake in the future.
|
|

January 22nd, 2010, 04:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Maybe it's related to the issue on page 410 described here: http://www.wrox.com/WileyCDA/WroxTit...Cd-ERRATA.html
Maybe VS infers a different parameter type. Does manually changing it do the trick?
Imar
|
|
 |