I'm trying to auto-populate a listbox of zip codes from a database table state_zipcode_plans based on the state a user selects from the previous listbox. I'm getting the error:
Must declare the scalar variable @state_code.
Any suggestions on fixing this?
Can it be fixed by adding in Request.Form("state_code"
fl0wmastr
Member
6 Points
3 Posts
Auto-populated Listbox based on selection from other Listbox
Feb 22, 2011 04:02 PM|LINK
I'm trying to auto-populate a listbox of zip codes from a database table state_zipcode_plans based on the state a user selects from the previous listbox. I'm getting the error: Must declare the scalar variable @state_code.
Any suggestions on fixing this?
Can it be fixed by adding in Request.Form("state_code"
) in somewhere?
Here's my code:<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
>
</
asp:SqlDataSource
>
<br class="style7"
/>
</td
>
<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
>
SelectParameters FormView ListBox asp.net
sansan
All-Star
53942 Points
8147 Posts
Re: Auto-populated Listbox based on selection from other Listbox
Feb 22, 2011 04:29 PM|LINK
Whenever you define parameters in SelectCommand, parameters should be defined in the SelectParameters as well..
SelectParameters FormView ListBox asp.net
fl0wmastr
Member
6 Points
3 Posts
Re: Auto-populated Listbox based on selection from other Listbox
Mar 07, 2011 03:08 PM|LINK
how is that different from what i had before?
SelectParameters FormView ListBox asp.net
sansan
All-Star
53942 Points
8147 Posts
Re: Auto-populated Listbox based on selection from other Listbox
Mar 07, 2011 05:09 PM|LINK
Only difference is adding the select parameter for the SqlDataSource to pass the State ID from the DropDownlist selection to filter Districts.