 |
BOOK: Beginning ASP.NET 4.5 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4.5 : 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
|
|
|
|
|

December 17th, 2013, 04:58 AM
|
|
Registered User
|
|
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Problems with DetailsView (Ch. 13)
Hi,
First of all let me say how much I am enjoying this book.
I'm having a relatively minor problem using the DetailsView control to insert data into my database. I've followed all of the instructions, but when I open the page Genre.aspx, instead of just having the option to add a name and sort order for a new record, I also get an extra field that allows input of an Id. When I insert a new record it is added ok, and the record is assigned an Id correctly (i.e. it ignores the Id I input into the text box, and is assigned automatically by the database.)
Here is my code:
Code:
<%@ Page Title="Planet Wrox - Management - Home" 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="cpMainContent" 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" />
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" InsertVisible="False" Visible="True" />
<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>
It appears similar to the code in the book, just not in the order it's printed in the book.
Edit: Actually upon using the quick diff tool to compare my code and the code from the book there are significant differences, my DetailsView doesn't seem to have any <asp:BoundField > elements. I ran the code from the book and it works perfectly.
Any idea why my auto-generated code would be so different? I followed the instructions to the letter.
Thanks for your help,
Justin
Last edited by waysgoose; December 17th, 2013 at 05:18 AM..
Reason: Clarification
|
|

December 17th, 2013, 07:31 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Did you mark the ID column as the primary key and an identity in the database?
Which exercise / page is this code coming from?
Cheers,
Imar
|
|

December 17th, 2013, 10:20 PM
|
|
Registered User
|
|
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
Thanks for you quick reply. The exercise I'm doing is "Try It Out: Inserting Data with the DetailsView Control", on page 463.
I used the script supplied in Chapter 12 Resources code to create my database, and I've checked both tables. Both tables have Id set as the primary key and an identity.
The part that is missing from my code is the 3 <asp:BoundField> fields shown in step 5 of the Try It Out exercise.
As I say, I tried the Genre.aspx code from the downloaded code and it works fine. But when I follow the try it out it doesn't work correctly.
Cheers,
Justin
|
|

December 18th, 2013, 07:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
HI Justin,
I just tried this myself and I am seeing the same issue. Somehow, VS doesn't have the correct schema information available when generating the DetailsView. To fix this, refresh the schema like this:
1. Follow steps 1 - 4 from the TIO on page 463
2. As a step 4a, click Refresh Schema on the DetailsView's Smart Tasks panel. Click No when asked to regenerate the fields for the GridView, but answer Yes when asked the same question for the DetailsView.
Based on the refreshed schema data, VS is then able to generate the correct fields.
Not sure if this is a bug or a feature. Looks like a bug to me, as you would assume VS refreshes the schema when it needs to create the DetailsView.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

December 18th, 2013, 08:15 AM
|
|
Registered User
|
|
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Thanks Imar!
I so appreciate the support you provide for your book. It is fantastic.
Your book is great too. I'm really enjoying working through it.
One again thanks so much.
Justin
|
|

December 18th, 2013, 09:24 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're welcome. Glad to hear you like the book so much.
Did my steps resolve the issue?
Imar
|
|

December 18th, 2013, 09:17 PM
|
|
Registered User
|
|
Join Date: Dec 2013
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
Yes refreshing the schema on the DetailsView did the trick
Something to bear in mind in my future programming in ASP.NET.
Thanks for your help,
Justin
|
|

December 19th, 2013, 03:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
Something to bear in mind in my future programming in ASP.NET.
|
Yes, and I'll include it in my upcoming Beginning ASP.NET 4.5.1. book as well.
Thanks for confirming.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

July 31st, 2014, 06:34 PM
|
|
Registered User
|
|
Join Date: Jul 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
AddEditReview example
I've tried the option to refresh the control and that worked but now I'm getting an error when trying to insert the data.
Input string is in the wrong format.
I'm not sure if its the book, source code, or VS 2013 but there are so many problems working through the examples.
I even purchased the 4.5.1 edition and it's the same.

|
|

August 1st, 2014, 06:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Can you be a bit more specific? When exactly do you get this error and for which page. Can you post the following:
1. The full address of the page in the browser.
2. The full error message
3. The code (markup and code behind) for the relevant pages?
The code in the book should work fine, so there must be something in your code that is breaking.
Cheers,
Imar
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Ch. 13 - PlanetWroxConnectionString1 |
hopper3011 |
BOOK: Beginning ASP.NET 4 : in C# and VB |
6 |
August 27th, 2012 02:19 AM |
| Chapter 13 - DetailsView Issue |
pgrant |
BOOK: Beginning ASP.NET 4 : in C# and VB |
4 |
April 11th, 2012 06:51 AM |
| another question in ch 13 |
nawar youssef |
BOOK: Beginning PHP 5.3 |
0 |
October 17th, 2011 12:40 AM |
| Ch 13-cms_articles_compose |
nuhbutt |
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 |
1 |
June 1st, 2010 12:28 PM |
| Search ch 13, ch 16 |
sporik |
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 |
0 |
October 27th, 2009 04:44 PM |
|
 |
|