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 July 1st, 2010, 02:17 PM
Registered User
 
Join Date: Jun 2010
Posts: 5
Thanks: 4
Thanked 0 Times in 0 Posts
Default Chapter 13 p.443 Try it out

I drop a DetailsView according to the instructions.

At Step 5 I set the DefaultMode as instructed, however, I notice the code doesn't setup the asp:BoundFields as in the example in the book. It looks like this after the Behavior property is set:
Code:
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" 
    DefaultMode="Insert" Height="50px" Width="125px">
    <Fields>
      <asp:CommandField ShowInsertButton="True" />
    </Fields>
  </asp:DetailsView>
Obviously, when the page is run the Id column of the sql table is insertable, which we don't want.

This isn't a big deal as I get how to fix it, I was just wondering what, if anything, I could be doing wrong here. The instructions seem clear enough and I've tried them twice.

I wouldn't mind having the opportunity to be lazy by not having to write the additional lines to configure the asp:BoundFields manually in cases where larger amounts of data are at play.

I also notice that the "AutoGenerateRows=False" and the "DataKeyNames=Id" properties aren't set in my code vs the code example in the book...maybe I have to set these manually every time? The books seems to suggest these properties will be autoset after pointing the control to the SqlDataSource control.
Thanks for your help.

Last edited by sycomputing; July 1st, 2010 at 03:13 PM.. Reason: Noticed something else...
 
Old July 2nd, 2010, 03:45 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 don't know why; that sometimes happens. I think it's a bug. What you see in the book is how it's supposed to work, and how it quite often, but not always works.

Another possible cause for this problem is that you forgot to turn the Id column of the table into an identity and primary key column.

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:
sycomputing (July 2nd, 2010)
 
Old July 2nd, 2010, 06:14 PM
Registered User
 
Join Date: Jun 2010
Posts: 5
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Bah...it's happening in the Chapter 14 p.499 try it out as well and the page doesn't work correctly.

Code:
<asp:DetailsView ID="DetailsView1" runat="server" 
    DataSourceID="EntityDataSource1" DefaultMode="Insert" Height="50px" 
    Width="125px">
    <Fields>
      <asp:CommandField ShowInsertButton="True" />
    </Fields>
  </asp:DetailsView>
My table id assignments and keys are correct...bummer.

Would someone mind posting the correct code for this Try it Out?
 
Old July 2nd, 2010, 06:27 PM
Registered User
 
Join Date: Jun 2010
Posts: 5
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Ok I got it to work.

Instead of deleting the control and starting from the beginning this time, I left the control there and just ran through steps 6 - 13 again.

Maybe I didn't do something correctly the first time.
 
Old July 3rd, 2010, 08:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Just curious, after I do the test insert at step 13 of this chapter, I open the table to look at the data and notice the new entry has an Id of 3.
Why isn't it 1? There have been no other entries in the table. It's brand new.
IDs are handed out by the database not only when a record is inserted successfully, butt sometimes also when an insert fails.
So, for example if you insert a record in the Pictures table with a reference to an AlbumId that does not exist in the Albums table, the insert fails and the record is not inserted in Pictures, but its identity may be increased nonetheless.

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:
sycomputing (July 3rd, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 rock1233 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 October 6th, 2009 12:18 PM
Chapter 13 bwoll BOOK: Beginning Access 2003 VBA 1 June 7th, 2007 03:57 PM
Chapter 13 ElMorenito BOOK: Beginning ASP 3.0 0 January 14th, 2005 02:56 PM
Chapter 13 p. 509 arienlee BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 July 31st, 2004 07:19 AM





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