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 October 20th, 2010, 03:26 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default Ch13 Page 443 - Step 5 problem

I followed steps 1-4 on page 443 and then set the default mode to "Insert".

However:
1: My Details view code does not look the same as shown in step 5. (see below)
2: The page renders and works BUT the "Id" column is shown which is not like Figure 13.6.

The "Identity Specification" for the Genre>Id column is set to "Yes".

Any clues?

Thanks
Ken

Code:
<%@ Page Title="Planet Wrox - Management Genres." Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Genres.aspx.cs" Inherits="Management_Genres" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

  <asp:GridView ID="GridView1" runat="server" 
  AllowPaging="True" 
  AllowSorting="True" 
  AutoGenerateColumns="False" 
  DataKeyNames="Id" 
  DataSourceID="SqlDataSource1" 
  EmptyDataText="There are no data records to display.">
  <Columns>
    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" ButtonType="link"/>
    <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True"  SortExpression="Id" />
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    <asp:BoundField DataField="SortOrder" HeaderText="SortOrder" SortExpression="SortOrder" />
  </Columns>
</asp:GridView>

 
  <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" 
    DefaultMode="Insert" Height="50px" Width="125px">
    <Fields>
      <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.ProviderName %>" 
  SelectCommand="SELECT [Id], [Name], [SortOrder] FROM [Genre]" 
  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>
</asp:Content>

Last edited by ken evans; October 20th, 2010 at 03:28 PM.. Reason: typo
 
Old October 20th, 2010, 03:29 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're missing the Field Definitions for the DetailsView:

Code:
 
<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
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 October 20th, 2010, 03:36 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

Well er - yes - I can see that.
But my point is that I followed the procedure in the book which I interpreted as meaning that the "missing code" would be written for me!

Did I misinterpret the book?
Am I expecting too much of VWD?

Thanks
Ken
 
Old October 20th, 2010, 05:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It' supposed to work as advertised in the book (as that's how I wrote it). However, VWD has some quirks when it comes to operations like this. You can try this:

1. Remove the DataSourceID attribute and its value from the DetailsView in Markup View

2. Save and close all open pages

3. Open the page again, switch to Design View and reassign the DataSourceID

If that fails, manually entering the code and/or reporting the bug to Microsoft would be the next logical steps.... ;-)

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!
The Following User Says Thank You to Imar For This Useful Post:
ken evans (October 25th, 2010)
 
Old October 25th, 2010, 04:09 AM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
Default

Steps 1-3 give the same result.
Entering the code manually works.

I tried to report the bug using Help>Report a Bug, but I could not log onto the Microsoft site. It just repeats the call every few seconds.
Same problem with trying to "Register" the product.

Cheers
Ken
 
Old October 25th, 2010, 05:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think you can directly log issues at http://connect.microsoft.com.

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 November 27th, 2010, 06:22 PM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Default It worked but only sometimes

Yes it does work; but not always for me. At first, VWD created the code as Ken Evans indicated which was incomplete . I then played around, trying different placements many times and perfect! . I then deleted the code to try and recreate the code, just to be sure before I posted anything, and ..... could not get the code to be created properly. I tried placing it everywhere without luck. So, as I need the practice anyway, I recreated the form, didn't do anything with the form after "Try It Out" [Using the GridView and SqlDataSource Contorls] and with the GridView still selected ( I double clicked on "Details View" control the code entered in perfect.

Hmmm...
 
Old November 27th, 2010, 06:44 PM
Registered User
 
Join Date: Aug 2010
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Default Details View

The problem may be something to do with page 441 where the text instructs us to add:
Code:
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
         ShowSelectButton="True" ButtonType="Button"></asp:CommandField>
My original code (see p440) looked like this (notice the closing "/>")
Code:
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                ShowSelectButton="True" />
This extra closing code was causing an error
Code:
></asp:CommandField>
But all I seemed to need was the existing closing statement.
Code:
/>
as on page 440, the extra code creates an extra closing ">".

When I recreated my Genres form I DID NOT add the buttons before I added the DetailsView control which generated the proper code.

Perhaps this had something to do with the code not being created properly.
 
Old November 28th, 2010, 06:14 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 there,

For this control it shouldn't make a difference whether you use a self closing tag or a separate one. E.g. the following two should be functionally equivalent:

Code:
 
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
     ShowSelectButton="True"></asp:CommandField>
 
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
     ShowSelectButton="True" />
Are you seeing behavior in Visual Studio that differs on how you define the CommandField?

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 27th, 2011, 10:52 AM
Registered User
 
Join Date: Mar 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Default Same problem for me (pg 443 step 5 ch13) no fields

I experienced the same problem, adding a DetailsView in ch. 13, no fields added. I tried Imar's suggested fix, removing the DataSourceID but that did not help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem on Chapter 11, page 356 step 5. Please Help! angelf BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 October 18th, 2010 03:11 AM
Chapter 5 page 156 Example Step 4 NoraBelle BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 1 August 2nd, 2010 03:29 PM
Chapter 13 p.443 Try it out sycomputing BOOK: Beginning ASP.NET 4 : in C# and VB 4 July 3rd, 2010 08:39 AM
Page 222 Step 5 Whitney Schopf BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 November 6th, 2006 06:43 AM
step of opening a web page somnath.kartic VS.NET 2002/2003 0 March 30th, 2006 03:24 AM





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