Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 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 February 21st, 2008, 12:45 PM
Authorized User
 
Join Date: Sep 2007
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB Ch8 p270 Try It Out Updating Existing Records

I unzipped the Chapter08 files and opened the Fixtures.aspx page as requested. At Step 8, I ran the page and the GridView is shown as expected. I managed to edit using the GridView control, but the DetailsView control is not displayed at all.

There is a TreeViewControl and associated XML datasource displayed, although there's no mention of this in the exercise.

Thinking I'd missed something, I deleted Chapter08 files and started again from the unzip, but after the second time through I still have a GridView and a TreeView, but no DetailsView.

In the Database Explorer, I noticed that I have two similar data connections: WroxUnited.mdf and WroxUnited.mdf1. In web.config, only the former is used, with connection strings associated with the GridView and the DetailsView.

I haven't yet checked the Chapter 8 errata.

Here is my code:

Code:
<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="Fixtures.aspx.vb" Inherits="Fixtures" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="FixtureID"
        DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
        <Columns>
            <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="FixtureID" HeaderText="FixtureID" ReadOnly="True" SortExpression="FixtureID" />
            <asp:BoundField DataField="FixtureDate" HeaderText="FixtureDate" SortExpression="FixtureDate" />
            <asp:BoundField DataField="Opponents" HeaderText="Opponents" SortExpression="Opponents" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WroxUnitedConnectionString1 %>"
        DeleteCommand="DELETE FROM [Fixtures] WHERE [FixtureID] = @FixtureID" InsertCommand="INSERT INTO [Fixtures] ([FixtureDate], [Opponents]) VALUES (@FixtureDate, @Opponents)"
        ProviderName="<%$ ConnectionStrings:WroxUnitedConnectionString1.ProviderName %>"
        SelectCommand="SELECT [FixtureID], [FixtureDate], [Opponents] FROM [Fixtures]"
        UpdateCommand="UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate, [Opponents] = @Opponents WHERE [FixtureID] = @FixtureID">
        <InsertParameters>
            <asp:Parameter Name="FixtureDate" Type="DateTime" />
            <asp:Parameter Name="Opponents" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="FixtureDate" Type="DateTime" />
            <asp:Parameter Name="Opponents" Type="String" />
            <asp:Parameter Name="FixtureID" Type="Int32" />
        </UpdateParameters>
        <DeleteParameters>
            <asp:Parameter Name="FixtureID" Type="Int32" />
        </DeleteParameters>
    </asp:SqlDataSource>
    <asp:DetailsView ID="DetailsView1" runat="server" DataKeyNames="FixtureID"
        DataSourceID="SqlDataSource2" Height="50px" Width="493px">
        <Fields>
            <asp:BoundField DataField="FixtureID" HeaderText="FixtureID" InsertVisible="False"
                ReadOnly="True" SortExpression="FixtureID" />
            <asp:BoundField DataField="FixtureDate" HeaderText="FixtureDate" SortExpression="FixtureDate" />
            <asp:BoundField DataField="FixtureType" HeaderText="FixtureType" SortExpression="FixtureType" />
            <asp:BoundField DataField="GoalsFor" HeaderText="GoalsFor" SortExpression="GoalsFor" />
            <asp:BoundField DataField="GoalsAgainst" HeaderText="GoalsAgainst" SortExpression="GoalsAgainst" />
            <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
            <asp:BoundField DataField="Opponents" HeaderText="Opponents" SortExpression="Opponents" />
            <asp:commandfield ShowEditButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:WroxUnitedConnectionString2 %>"
        SelectCommand="SELECT [FixtureID], [FixtureDate], [FixtureType], [GoalsFor], [GoalsAgainst], [Notes], [Opponents] FROM [Fixtures] WHERE ([FixtureID] = @FixtureID)" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [Fixtures] WHERE [FixtureID] = @original_FixtureID AND [FixtureDate] = @original_FixtureDate AND [FixtureType] = @original_FixtureType AND [GoalsFor] = @original_GoalsFor AND [GoalsAgainst] = @original_GoalsAgainst AND [Notes] = @original_Notes AND [Opponents] = @original_Opponents" InsertCommand="INSERT INTO [Fixtures] ([FixtureDate], [FixtureType], [GoalsFor], [GoalsAgainst], [Notes], [Opponents]) VALUES (@FixtureDate, @FixtureType, @GoalsFor, @GoalsAgainst, @Notes, @Opponents)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Fixtures] SET [FixtureDate] = @FixtureDate, [FixtureType] = @FixtureType, [GoalsFor] = @GoalsFor, [GoalsAgainst] = @GoalsAgainst, [Notes] = @Notes, [Opponents] = @Opponents WHERE [FixtureID] = @original_FixtureID">
        <SelectParameters>
            <asp:controlparameter ControlID="GridView1" Name="FixtureID" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
        <deleteparameters>
            <asp:parameter Name="original_FixtureID" Type="Int32" />
            <asp:parameter Name="original_FixtureDate" Type="DateTime" />
            <asp:parameter Name="original_FixtureType" Type="String" />
            <asp:parameter Name="original_GoalsFor" Type="Int16" />
            <asp:parameter Name="original_GoalsAgainst" Type="Int16" />
            <asp:parameter Name="original_Notes" Type="String" />
            <asp:parameter Name="original_Opponents" Type="String" />
        </deleteparameters>
        <updateparameters>
            <asp:parameter Name="FixtureDate" Type="DateTime" />
            <asp:parameter Name="FixtureType" Type="String" />
            <asp:parameter Name="GoalsFor" Type="Int16" />
            <asp:parameter Name="GoalsAgainst" Type="Int16" />
            <asp:parameter Name="Notes" Type="String" />
            <asp:parameter Name="Opponents" Type="String" />
            <asp:parameter Name="original_FixtureID" Type="Int32" />
            <asp:parameter Name="original_FixtureDate" Type="DateTime" />
            <asp:parameter Name="original_FixtureType" Type="String" />
            <asp:parameter Name="original_GoalsFor" Type="Int16" />
            <asp:parameter Name="original_GoalsAgainst" Type="Int16" />
            <asp:parameter Name="original_Notes" Type="String" />
            <asp:parameter Name="original_Opponents" Type="String" />
        </updateparameters>
        <insertparameters>
            <asp:parameter Name="FixtureDate" Type="DateTime" />
            <asp:parameter Name="FixtureType" Type="String" />
            <asp:parameter Name="GoalsFor" Type="Int16" />
            <asp:parameter Name="GoalsAgainst" Type="Int16" />
            <asp:parameter Name="Notes" Type="String" />
            <asp:parameter Name="Opponents" Type="String" />
        </insertparameters>
    </asp:SqlDataSource>
    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="Schedule2007XML">
        <DataBindings>
            <asp:TreeNodeBinding DataMember="Game" TextField="#Value" />
            <asp:TreeNodeBinding DataMember="Home" TextField="#InnerText" />
            <asp:TreeNodeBinding DataMember="Date" TextField="#InnerText" />
            <asp:TreeNodeBinding DataMember="Visitor" TextField="#InnerText" />
        </DataBindings>
    </asp:TreeView>
    <asp:XmlDataSource ID="Schedule2007XML" runat="server" DataFile="~/Schedule2007.xml">
    </asp:XmlDataSource>

</asp:Content>
Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
__________________
Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
 
Old February 28th, 2008, 05:55 AM
Authorized User
 
Join Date: Sep 2007
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The 3rd time through, the exercise seemed to work as expected with a few adjustments noted here.
In Step 3, when selecting the connection string for the DetailsView data source, selecting WroxUnitedConnectionString brought up a message saying something about trying to access a Chapter07 database. I had to navigate to Chapter08/App_Data to locate the correct one and this created a new connection string.
In Step 4, after setting GridView1 for the Control ID, I set the default value to 1.
The 'separate' behaviour of the GridView and DetailsView editing feature is rather odd - not updating the one when using the other. This isn't explained until p277. A reference to it would have been nice to answer possible reader questions.

Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a new record between two existing records hsncompany BOOK: Beginning Access 2003 VBA 0 April 13th, 2008 03:36 PM
VB Chap 8 p270 Try It Out bking83485 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 December 3rd, 2007 12:01 AM
problem in updating records & finding records naveed77 VB Databases Basics 1 January 16th, 2007 12:12 PM
problem in updating records & finding records naveed77 VB How-To 1 January 16th, 2007 12:10 PM
Updating an Existing Website to XHTML and CSS funksoulkitty HTML Code Clinic 2 April 3rd, 2006 05:51 PM





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