Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 October 18th, 2010, 09:34 AM
Registered User
 
Join Date: Oct 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 12, page 400 SqlDataSource1

The Reviews.aspx returns an error:

Code:
The DataSourceID of 'DropDownList1' must be the ID of a control of type IDataSource.  A control with ID 'SqlDataSource1' could not be found. 
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.Web.HttpException: The DataSourceID of 'DropDownList1' must be the ID of a control of type IDataSource.  A control with ID 'SqlDataSource1' could not be found.

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: 


[HttpException (0x80004005): The DataSourceID of 'DropDownList1' must be the ID of a control of type IDataSource.  A control with ID 'SqlDataSource1' could not be found.]
   System.Web.UI.WebControls.DataBoundControl.GetDataSource() +8559526
   System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView() +37
   System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e) +19
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
My Source Code I think the connection string for SqlDataSource1 is missing, but I am not certain where I should put that. When I put it after the ASP link for SqlDataSource2, I get a 'not well formed' error which tells me it I may be tying the data source to the wrong control.
Code:
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" 
        DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id">
            <asp:ListItem Value="">Please make a selection</asp:ListItem>
        </asp:DropDownList>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource2">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Summary" HeaderText="Summary" SortExpression="Summary" />
                <asp:BoundField DataField="Body" HeaderText="Body" SortExpression="Body" />
                <asp:BoundField DataField="GenreId" HeaderText="GenreId" SortExpression="GenreId" />
                <asp:CheckBoxField DataField="Authorized" HeaderText="Authorized" SortExpression="Authorized" />
                <asp:BoundField DataField="CreateDateTime" HeaderText="CreateDateTime" SortExpression="CreateDateTime" />
                <asp:BoundField DataField="UpdateDateTime" HeaderText="UpdateDateTime" SortExpression="UpdateDateTime" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
        SelectCommand="SELECT * FROM [Review] WHERE ([GenreId] = @GenreId)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="GenreId" PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    
    </ContentTemplate>
    </asp:UpdatePanel>
    
</asp:Content>
 
Old October 18th, 2010, 11:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Quote:
I think the connection string for SqlDataSource1 is missing
The connection string is not missing, the entire data source control is missing.
Quote:
A control with ID 'SqlDataSource1' could not be found.
The error message is correct; all I see is an SqlDataSource control called SqlDataSource2....

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!
 
Old October 18th, 2010, 12:51 PM
Registered User
 
Join Date: Oct 2010
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I know the connection string is missing. I was wondering where it needed to be. Did not see it last night in the source file.

Got it now that I have slept and had time to revisit the issue. I can wonder wonder what step I messed up...

Thank you.

Code:
</asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
        
        SelectCommand="SELECT * FROM [Review] WHERE ([GenreId] = @GenreId)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="GenreId" PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]"></asp:SqlDataSource>    </ContentTemplate>
    </asp:UpdatePanel>
 
Old October 19th, 2010, 04:18 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,
Quote:
Yes, I know the connection string is missing.
That's not what I said. The connection string wasn't missing, the entire Data Source control was missing. E.g. the error said "A control with ID 'SqlDataSource1' could not be found.:" which is correct as your code only contained a control called SqlDataSource2.

Anyway, looks like you missed some steps from the exercise on page 397 and further where the SqlDataSource is added. Or maybe you didn't save your changes when you closed the file or undid some steps.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 12 Page 414 Try it out JohnKiller BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 August 10th, 2010 03:17 PM
Chapter 12 Page 410 Try it out JohnKiller BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 August 10th, 2010 02:49 PM
Chapter 12 Try It Out: Applying Filter (pg 400) Deepeshk ASP.NET 3.5 Basics 2 July 12th, 2008 10:28 AM
Chapter 12 (page 400) Try It Out: Applying Filter Deepeshk BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:18 AM
Chapter 12: Page 410 - Try it out VeganMan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 20th, 2008 03:44 PM





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