Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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
  #1 (permalink)  
Old January 19th, 2007, 04:17 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default SqlDataSource control error

Hello:

I am having a little issue with an error that is frustrating me. I have a SqlDataSource within an asp:label control and also have a two dropdownlists inside that asp:label control also. When I select from the first dropdownlist, it should enable the second dropdownlist with the populated data, but instead I receive.

The SqlDataSource control 'sqlGetMLSByCity' does not have a naming container. Ensure that the control is added to the page before calling DataBind.

Any ideas why this would be? Here is the web from portion:

<asp:Label ID="recip_form_request" runat="server" Visible="false">
    [list]
        <li>Step one: Select listing type.</li>
        <li>Step two: Select the City that you are reciprocating to.</li>
        <li>Step three: Complete the Recip Form.</li>
    </ul>
    <asp:DropDownList ID="recip_form_type" runat="server" AutoPostBack="true" Visible="False">
        <asp:ListItem Value="0" Text="(Select Form)"></asp:ListItem>
        <asp:ListItem Value="1" Text="Residential"></asp:ListItem>
    </asp:DropDownList>
    <br />
    <asp:DropDownList ID="outside_assoc_cities" runat="server" AutoPostBack="True" Enabled="False" DataTextField="city" DataValueField="id" Visible="False"></asp:DropDownList><br />
    <asp:Label ID="city_mls_desc" runat="server"></asp:Label><br />
    <asp:Button ID="page1_btn" runat="server" Text="Next >>" Visible="False" />
    <asp:SqlDataSource ID="sqlCities" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ AppSettings:connectionstring %>" SelectCommandType="Text" SelectCommand="SELECT id, city FROM tCityMaster"></asp:SqlDataSource>
    <asp:SqlDataSource ID="sqlGetMLSByCity" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ AppSettings:connectionstring %>">
        <SelectParameters>
            <asp:ControlParameter ControlID="outside_assoc_cities" Name="City" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Label>

then the code behind:

Protected Sub outside_assoc_cities_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles outside_assoc_cities.SelectedIndexChanged
        If outside_assoc_cities.SelectedIndex > -1 Then
            Dim ItemId As Integer = Integer.Parse(outside_assoc_cities.SelectedValue)
            Dim MLSID As String = Nothing

            Dim cmd As New SqlCommand
            Dim con As New SqlConnection
            cmd.Connection = con

            Dim sqlGetMLSByCity_sql As SqlDataSource = CType(Page.FindControl("sqlGetMLSByCity"), SqlDataSource)
            'using connectionstring from SqlDataSource Control
            con.ConnectionString = sqlGetMLSByCity_sql.ConnectionString
            'con.ConnectionString = sqlGetMLSByCity.ConnectionString

            cmd.CommandType = CommandType.Text
            cmd.CommandText = "SELECT mls_id FROM pwaordev..tCityMaster WITH(NOLOCK) WHERE ID=@ID"

            cmd.Parameters.Add("@ID", SqlDbType.Int, 4).Value = ItemId

            Try
                con.Open()
                MLSID = cmd.ExecuteScalar
                con.Dispose()
                cmd.Dispose()
            Catch ex As Exception
                con.Dispose()
                cmd.Dispose()
                Response.Write(ex.ToString())
            End Try

            'Further logic to display button depending on MLS
            If Not String.IsNullOrEmpty(MLSID) Then
                If MLSID = "B" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Greater South Bay MLS."
                    page1_btn.Visible = True
                ElseIf MLSID = "A" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Big Bear BOR, MLS, which is not covered by Pacific West Association of REALTOR&reg, please contact us for more information."
                    page1_btn.Visible = False
                ElseIf MLSID = "C" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Combined L.A./Westside MLS."
                    page1_btn.Visible = True
                ElseIf MLSID = "F" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Crisnet MLS, which is not covered by Pacific West Association of REALTOR&reg, please contact us for more information."
                    page1_btn.Visible = False
                ElseIf MLSID = "Y" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is DCAoR - Yucca Valley Area, which is not covered by Pacific West Association of REALTOR&reg, please contact us for more information."
                    page1_btn.Visible = False
                ElseIf MLSID = "D" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Desert Area MLS."
                    page1_btn.Visible = True
                ElseIf MLSID = "L" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is i-Tech Glendale/Pasadena."
                    page1_btn.Visible = True
                ElseIf MLSID = "M" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is MRM - Multi-Regional MLS."
                    page1_btn.Visible = True
                ElseIf MLSID = "R" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is RIM - Rim of the World MLS, which is not covered by Pacific West Association of REALTOR&reg, please contact us for more information."
                    page1_btn.Visible = False
                ElseIf MLSID = "G" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is SDI - San Diego, which is not covered by Pacific West Association of REALTOR&reg, please contact us for more information."
                    page1_btn.Visible = False
                ElseIf MLSID = "S" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is SOCAL MLS - Southern California MLS."
                    page1_btn.Visible = True
                ElseIf MLSID = "T" Then
                    city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Outside Area, which is not covered by Pacific West Association of REALTOR&reg, please contact us for more information."
                    page1_btn.Visible = False
                End If
                'test.Text = MLSID
                'If test.Text = "L" Then
                'mls_text.Text = "i-Tech"
                'End If
            End If
        End If
    End Sub

Any help would be great, thank you!

  #2 (permalink)  
Old January 19th, 2007, 08:02 PM
Authorized User
 
Join Date: Dec 2006
Location: , , .
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed, I removed visible=false off the controls and cleaned up the vb code.



Similar Threads
Thread Thread Starter Forum Replies Last Post
SqlDataSource ControlParameter Cannot Find Control AspNetGuy ASP.NET 3.5 Basics 1 June 25th, 2008 07:44 AM
Binding SQLDataSource To A Label Control sg225551 ASP.NET 2.0 Basics 1 January 16th, 2008 10:36 AM
Need help with SqlDataSource control binici ASP.NET 2.0 Basics 1 February 5th, 2007 05:32 PM
SqlDatasource filter using formview control tony_j_hug ASP.NET 2.0 Basics 2 October 17th, 2005 05:55 AM





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