PDA

View Full Version : Dynamically changing 2nd drop down value according to first drop down


empyrean
11-30-2009, 11:42 PM
i tried to some extent in solving this. looks like everything is good but i dont know why it is not taking it as parameter?? i am getting the error ("ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the variable '@Crop_ID'.")

Please check my code and suggest me something as my proj depends on linking the dropdowns and populating the list box at the end.. i am new to web development and unable to find the error...

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Report_csharp.aspx.cs" Inherits="Report_csharp" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="lb_Crop" runat="server" Text="Crop Name:"></asp:Label>
<asp:DropDownList ID="ddl_Crop" runat="server" AutoPostBack="true" AppendDataBoundItems="true"
OnSelectedIndexChanged="ddl_Crop_SelectedIndexChanged"
DataSourceID="SDS_Crop" DataTextField="CropName" DataValueField="Crop_ID">
</asp:DropDownList>
<asp:Label ID="lb_Project" runat="server" Text="Project Name:"></asp:Label>
<asp:DropDownList ID="ddl_proj" runat="server" AutoPostBack="True"
DataSourceID="SDS_Proj" DataTextField="Project_ID"
DataValueField="Crop_ID">
</asp:DropDownList>
<asp:SqlDataSource ID="SDS_Proj" runat="server"
ConnectionString="<%$ ConnectionStrings:PlanOfWorkConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:PlanOfWorkConnectionString1.ProviderName %>"
SelectCommand="SELECT [Crop_ID], [Project_ID] FROM [Project_Table]WHERE ([Crop_ID]=@Crop_ID)">
<SelectParameters>
<asp:ControlParameter ControlID = "ddl_Crop" Name = "Crop_ID" PropertyName = "SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SDS_Crop" runat="server" ConnectionString="<%$ ConnectionStrings:PlanOfWorkConnectionString1 %>"
SelectCommand="SELECT [CropName], [Crop_ID] FROM [Crop_Table]"
ProviderName="<%$ ConnectionStrings:PlanOfWorkConnectionString1.ProviderName %>"></asp:SqlDataSource>
</asp:Content>

SouthwaterDave
12-03-2009, 09:29 PM
If you are attempting what I think you are then you need to use AJAX. See http://www.asp.net/learn/Ajax-Control-Toolkit/tutorial-15-vb.aspx for a demo and the code to achieve it.

jonweb2009
12-27-2009, 10:34 PM
<asp:ControlParameter ControlID = "ddl_Crop" Name = "Crop_ID" PropertyName = "SelectedValue" Type="Int32" />
</SelectParameters>

it is may be because of the spaces in the above line your code seems fine. try removing spaces


favourite sites

http://www.******************