Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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 April 16th, 2015, 06:03 PM
Registered User
 
Join Date: Aug 2014
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
Default Using DropDown SelectedValues for Select statement

Scenario: I am trying to get values from 2 Dropdown selections so that I can display associated data from my database 'HighSchoolFootballTeam. I have gotten the error messages:
'The multi-part identifier "DropDownClass.SelectedValue" could not be bound.'

'The multi-part identifier "DropDownRegion.SelectedValue" could not be bound.'

'Invalid column name 'HighSchoolTeam'.'

Code:
        <WizardSteps>

            <asp:WizardStep runat="server" >
                <asp:DropDownList ID="DropDownSearchBy" runat="server" OnTextChanged="DropDown_TextChanged">
                    <asp:ListItem>Drop Down for Choices</asp:ListItem>
                    <asp:ListItem Value="Class">Classification</asp:ListItem>
                    <asp:ListItem Value="County">County</asp:ListItem>
                    <asp:ListItem Value="All">High School Team(s)</asp:ListItem>
                </asp:DropDownList>
            </asp:WizardStep>

            <asp:WizardStep runat="server" >
                <asp:DropDownList ID="DropDownClass" runat="server" Width="100px" OnTextChanged="DropDown_TextChanged">
                    <asp:ListItem Value="A">A</asp:ListItem>
                    <asp:ListItem Value="AA">AA</asp:ListItem>
                    <asp:ListItem Value="AAA">AAA</asp:ListItem>
                    <asp:ListItem Value="AAAA">AAAA</asp:ListItem>
                    <asp:ListItem Value="AAAAA">AAAAA</asp:ListItem>
                    <asp:ListItem Value="AAAAAA">AAAAAA</asp:ListItem>
                </asp:DropDownList>
            </asp:WizardStep>

            <asp:WizardStep runat="server" >
                <asp:DropDownList ID="DropDownRegion" runat="server" Width="100px" OnTextChanged="DropDown_TextChanged">
                    <asp:ListItem Value="1">1</asp:ListItem>
                    <asp:ListItem Value="2">2</asp:ListItem>
                    <asp:ListItem Value="3">3</asp:ListItem>
                    <asp:ListItem Value="4">4</asp:ListItem>
                    <asp:ListItem Value="5">5</asp:ListItem>
                    <asp:ListItem Value="6">6</asp:ListItem>
                    <asp:ListItem Value="7">7</asp:ListItem>
                    <asp:ListItem Value="8">8</asp:ListItem>
                </asp:DropDownList>
            </asp:WizardStep>

            <asp:WizardStep runat="server" Title="High School Team by Class &amp; Region">
                <asp:DropDownList ID="DropDownClassRegion" runat="server" DataSourceID="SqlDataSource2" DataTextField="HighSchoolName"  DataValueField="HighSchoolName" Width="100px">
                </asp:DropDownList>
                <asp:SqlDataSource  ID="SqlDataSource2" 
                                    runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:FollowingHSFootballConnectionString %>" 
                                    SelectCommand="SELECT [HighSchoolTeam] FROM [HighSchoolFootballTeam$] WHERE [Classification] = DropDownClass.SelectedValue and [Region] = DropDownRegion.SelectedValue"> 
                                    <SelectParameters>
                                        <asp:ControlParameter Name="Class" ControlID="DropDownClass" PropertyName="SelectedValue" />
                                    </SelectParameters>
                                    <SelectParameters>
                                        <asp:ControlParameter Name="Region" ControlID="DropDownRegion" PropertyName="SelectedValue" />
                                    </SelectParameters>
                </asp:SqlDataSource>
            </asp:WizardStep>
The database table is as follows:

Column Name Data Type Allow nulls

HighSchoolTeamID int Unchecked
Year int Checked
HighSchoolName varchar(50) Checked
Association varchar(50) Checked
Region int Checked
Classification varchar(50) Checked
County varchar(50) Checked
HomeStadiumID int Checked
Wins smallint Checked
Losses smallint Checked
TwitterFeed varchar(50) Checked
NewspaperID int Checked
AudioInternetLink varchar(50) Checked
VideoInternetLink varchar(50) Checked
SecondaryNewspaperID int Checked

What do you recommend for correcting this?

Thank You,
Michael
 
Old April 17th, 2015, 03:52 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,

Your SELECT statement is off. You currently have this:

WHERE [Classification] = DropDownClass.SelectedValue and [Region] = DropDownRegion.SelectedValue

This sends the hard coded value of DropDownClass.SelectedValue into the SQL statement which leads to the error you're getting.

When you set up the SqlDataSource you can select various parameters which should end up looking like this instead:

WHERE [Classification] = @Class and [Region] = @Region

Hope this helps,

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 April 17th, 2015, 10:33 AM
Registered User
 
Join Date: Aug 2014
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
Default Success

Imar,

Thank You so much! Between that and typing the correct column name, it worked! Much appreciated!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Row values from Dropdown Bronach XSLT 0 July 3rd, 2011 11:36 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Displaying Records From SELECT dropdown mgordon Classic ASP Databases 12 August 3rd, 2005 12:27 PM
select value of a dropdown in a datagrid Sbartis ASP.NET 1.0 and 1.1 Professional 2 January 14th, 2005 05:19 PM
Access SQL Statement to Format a Dropdown List jonesl3 Access 3 November 24th, 2004 10:08 AM





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