Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3988122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:12:53+00:00 2026-05-20T06:12:53+00:00

I want a listbox to auto-populate zip codes once a state is selected from

  • 0

I want a listbox to auto-populate zip codes once a state is selected from another listbox based on values defined in the state_zipcode_plans table from the database.
EX: If the state of FL is selected, load zip_codes (332, 333, 334, 335) where state_code=selected_state_code (FL) into the listbox

I get the error: Must declare the scalar variable @statecode with the existing code.

I was thinking maybe I should put Request.Form(“state_code”) in there somewhere?
My friend suggested adding a line in the CS code behind but I’m not sure about the syntax.
How do I make it work?

Here’s the code I have:

<asp:ListBox ID="ST_Select_ListBox" runat="server" DataSourceID="SqlDataSource1" 
DataTextField="state_code" DataValueField="state_code" CssClass="style7"></asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:PriceFinderConnectionString %>" 
SelectCommand="SELECT [state_code] FROM [state_code] ORDER BY [state_code]">
    <SelectParameters>
        <asp:FormParameter DefaultValue="NULL" FormField="state_code" Name="state_code" Type="String" />
    </SelectParameters>

             <td class="style2"> <span class="style7">Select Zip (auto-populated based on selected State)
                                </span>
                                <br class="style7" />
<br class="style7" />
<asp:ListBox ID="Zip_Select_ListBox" runat="server" DataSourceID="SqlDataSource2" CssClass="style7">
</asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:PriceFinderConnectionString %>" 
    SelectCommand="SELECT DISTINCT [zip_code] FROM [state_zipcode_plans] WHERE ([state_code] = @state_code)" Request.Form("state_code")>
    <SelectParameters>
        <asp:FormParameter DefaultValue="NULL" FormField="zip_code" Name="zip_code" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

Here’s the codebehind in C#:

    protected void Search_STZipPlan_Button_Click(object sender, EventArgs e)
    {

        SqlConnection conn = new SqlConnection("Server=localhost;Database=PriceFinder;Integrated Security=SSPI");
        conn.Open();

        SqlCommand searchPF = new SqlCommand("up_SelectPriceFinderResults", conn); //calling stored procedure 
        searchPF.CommandType = CommandType.StoredProcedure;


        SqlConnectionStringBuilder builder =  new SqlConnectionStringBuilder();
        builder["Data Source"] = "SqlDataSource1";
        builder["integrated Security"] = true;
        builder["Initial Catalog"] = "PriceFinder;NewValue=Bad";
        Console.WriteLine(builder.ConnectionString);

        SqlParameter state_code = new SqlParameter("state_code", SqlDbType.VarChar, 3); 
        SqlParameter zip_code = new SqlParameter("zip_code", SqlDbType.VarChar, 6); 
        SqlParameter plan_name = new SqlParameter("plan_name", SqlDbType.VarChar, 16);

        // SqlDataReader reader = SqlCommand.ExecuteReader();
        // Search_Results_GridView.DataSource = reader;

        Search_Results_GridView.DataBind();

        conn.Close();

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:12:53+00:00Added an answer on May 20, 2026 at 6:12 am

    The problem is SQL related. There probably is a mistake in the stored procedure

     up_SelectPriceFinderResults
    

    Since I don’t See the stored procedure’s source code, I presume you forgot to declare a parameter or a variable. You’ll have to declare the variable @state_code inside your stored procedure:

     declare @state_code varchar(3)
    

    or as a parameter of the stored procedure. Anyway, check the source code of the stored procedure:

    exec sp_helptext up_SelectPriceFinderResults
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox control that I want to change into having a toggle
I have a ListBox which displays items of variable height. I want to show
To make sure that the text in listbox items is not truncated I want
I am adding items to a ListBox like so: myListBox.Items.addRange(myObjectArray); and I also want
I'm using a controlTemplate of the ListBox to show a collection. I want to
It's easy to bind something to the SelectedIndex of the ListBox, but I want
I'm writing a Silverlight application. I want a Listbox that displays the rows vertically.
Curve the border of silverlight listbox control: I just want to curve the ends
Apologies for the ambiguous title. I want the items of my listbox to display
I want to bind the Height of the ListBox to the Height of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.