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

September 28th, 2011, 02:16 PM
|
|
Authorized User
|
|
Join Date: Sep 2011
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Chapter 14, Listview control problem
I am working through the Try It Out that starts on page 505 and have gotten to page 510 where it says to launch NewPhotoAlbum.asxp and put in a name for an album and click Insert.
When I click insert instead of being directed to the ManagePhotoAlbum.aspx page I get the following error:
Code:
Server Error in '/' Application.
For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.]
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +738
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
System.Web.UI.WebControls.ListView.PerformSelect() +113
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
System.Web.UI.WebControls.ListView.CreateChildControls() +55
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
Here is the code from my ManagePhotoAlbum.aspx:
Code:
<%@ Page Title="Manage Photo Album" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="managePhotoAlbum.aspx.cs" Inherits="_managePhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id"
DataSourceID="EntityDataSource1" InsertItemPosition="LastItem">
<InsertItemTemplate>
<li style="">
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
Tooltip:
<asp:TextBox ID="TooltipTextBox" runat="server" Text='<%# Bind("Tooltip") %>' />
<br />
ImageUrl:
<asp:TextBox ID="ImageUrlTextBox" runat="server"
Text='<%# Bind("ImageUrl") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</li>
</InsertItemTemplate>
<ItemTemplate>
<li style="">
Description:
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' />
<br />
Tooltip:
<asp:Label ID="TooltipLabel" runat="server" Text='<%# Eval("Tooltip") %>' />
<br />
ImageUrl:
<asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("ImageUrl") %>' />
<br />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul class="ItemContainer">
<li runat="server" id="itemPlaceholder" />
</ul>
</LayoutTemplate>
</asp:ListView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=PlanetWroxEntities"
DefaultContainerName="PlanetWroxEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EntitySetName="Pictures"
Where="it.PhotoAlbumId = @photoAlbumId"
oninserting="EntityDataSource1_Inserting" EntityTypeFilter="" Select="">
<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
And here is the code from my code behind file:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PlanetWroxModel;
public partial class _managePhotoAlbum : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void EntityDataSource1_Inserting(object sender, EntityDataSourceChangingEventArgs e)
{
int photoAlbumId = Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"));
Picture myPicture = (Picture)e.Entity;
myPicture.PhotoAlbumId = photoAlbumId;
}
}
Please let me know if you need further information and thanks in advance for any help you may be able to provide.
Sam
__________________
Noob, whole noob, nothing but a noob, so help me God. I will learn if it kills me.....
|
|

September 28th, 2011, 02:35 PM
|
|
Authorized User
|
|
Join Date: Sep 2011
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
I was able to fix this, even if I am not sure the exact "why" of it. I compared my code to the source code for the chapter that I downloaded and found out I was missing the following code on my aspx page:
Code:
...
<WhereParameters> <asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" Type="Int32" /> </WhereParameters>
...
I followed the directions in the book very well, or at least I thought I did so I do not understand why that part would be missing. I am just glad I found it.
If someone can explain the "why" factor here or what step I may have missed to get that part in I would appreciate it, that is the best way to learn.
Thanks!!
__________________
Noob, whole noob, nothing but a noob, so help me God. I will learn if it kills me.....
|
|

September 28th, 2011, 02:45 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Sam,
Did you also carry out the step below image 14-13:
Quote:
|
Make sure you enter it.PhotoAlbum.Id = @photoAlbumId in the Where Expression box at the top of the dialog. Next, click the Show Advanced Properties link and change the Type property of the parameter to Int32. When youâre done, click OK to dismiss the dialog box.
|
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

September 28th, 2011, 02:47 PM
|
|
Authorized User
|
|
Join Date: Sep 2011
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
You know, Imar,
I do not remember if I did or not, its so easy when working on this stuff after about the 7th hour in the day to start wanting to go to fast through the book. And when I went back to read it the second time I missed it for sure.
Thank you for pointing that out to me and I will be more careful next time.
__________________
Noob, whole noob, nothing but a noob, so help me God. I will learn if it kills me.....
|
|
 |
|