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

October 20th, 2010, 03:26 PM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
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
|
|

October 20th, 2010, 03:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

October 20th, 2010, 03:36 PM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
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
|
|

October 20th, 2010, 05:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

October 25th, 2010, 04:09 AM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 56
Thanks: 17
Thanked 2 Times in 2 Posts
|
|
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
|
|

October 25th, 2010, 05:24 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think you can directly log issues at http://connect.microsoft.com.
Cheers,
Imar
|
|

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

November 27th, 2010, 06:44 PM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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.
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.
|
|

November 28th, 2010, 06:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

July 27th, 2011, 10:52 AM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |
|