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

January 19th, 2014, 06:25 PM
|
|
Authorized User
|
|
Join Date: Jan 2014
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Visual Studio 2010 Professional & DetailsView control
Hello,
I just wanted to check and see if it's something I did wrong, but I followed the instructions for dragging & dropping the DetailsView control into the Genres.aspx page as specified in the Try It Out exercise on Chapter 13, page 443.
The GridView control worked just fine, dragging & dropping it set everything up perfectly. However, when I tried to add the DetailsView control afterwards, it wasn't quite so neat.
Here's what I did, exactly:
1.) Dragged a DetailsView control onto the SqlDataSource control in design view. It added it between the GridView and SqlDataSource controls just fine.
2.) Opened the DetailsView Smart Tasks Panel and chose the same data source used by the GridView control (SqlDataSource1)
3.) Checked off "Enable Inserting" in the Smart Tasks Panel
4.) Pressed F4 on my keyboard to go to the Properties Grid, located the DefaultMode property and set it to Insert.
I then went into Markup View as you instructed, and noticed that the generated code for the DetailsView was missing quite a bit. It never inserted AutoGenerateRows="False" or DataKeyNames="Id" into the asp:DetailsView control.
Also, under <Fields>....</Fields> the only entry I saw was <asp:CommandField ShowInsertButton="True">
All three of the asp:BoundField were not generated. I had to type them in manually. Once I added those things it worked as presented in the book.
Maybe my version of Visual Studio doesn't recognize the right things to do when setting the data source because it's not configured properly... Or maybe I left a step out? I am not sure.
Thanks in advance for your help.
|
|

January 19th, 2014, 06:31 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
This may be a bug in Visual Studio. Another reader ran into this some time ago as well.
Here's what I have added in my upcoming Beginning ASP.NET 4.5.1. book to work around the issue:
Quote:
|
If you don’t see the three BoundField elements, open the Smart Task panel for the DetailsView, click Refresh schema, click No when asked to refresh the fields and keys for the GridView, but click Yes when asked the same question for the DetailsView. This leaves the GridView unmodified and then correctly adds the fields for the DetailsView.
|
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

January 19th, 2014, 06:49 PM
|
|
Authorized User
|
|
Join Date: Jan 2014
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Thanks Imar!
That worked like a charm. Guess it is a bug in VS 2010 Pro. :)
|
|

January 20th, 2014, 07:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It still is an issue in VS 2013. For some reason, VS loses the meta data about the table making it impossible to set up the correct control properties and fields.
Imar
|
|

January 20th, 2014, 09:59 PM
|
|
Authorized User
|
|
Join Date: Jan 2014
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Hmm, interesting. Thank you for the update. :)
Oh here's one for you to ponder. Say I was building a hypothetical form in which an end user is setting up a reservation for themselves, as well as N other people. I would first ask them how many additional people besides themselves would be attending.
The form would then duplicate the input fields - nothing complex, just first name, last name and age of each person, N+1 times (to accommodate the original customer and the extra N attendees)
How would I go about setting this up in a single submission that would loop through each set of first name / last name / age (N+1 times) and insert them one at a time into the database?
Thanks in advance!
|
|

January 21st, 2014, 05:25 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
This Google search may come in handy: https://www.google.com/#q=asp+net+cr...ls+dynamically
It's a bit out of the scope of the book to discuss here, but hopefully the first couple of links will show you how to accomplish that.
Cheers,
Imar
|
|
 |
|