Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two combo box named as
1) cmbCountryId
2) cmbStateId

I bind this two combo box with SQLDataSource

For Country Combo Box
<asp:SqlDataSource ID="DS_Country" runat="server" ConnectionString="Data Source=.;Initial Catalog=Db_ESmart;Integrated Security=True"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CountryMasterId], [CountryName] FROM [CountryMaster] where IsDeleted=1 and IsActive=1">
        </asp:SqlDataSource>


For State Combo Box
<asp:SqlDataSource ID="DS_State" runat="server" ConnectionString="Data Source=.;Initial Catalog=Db_ESmart;Integrated Security=True"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT [StateMasterId], [CountryMasterId], [StateName] FROM [StateMaster] WHERE ([CountryMasterId] = @CountryMasterId)">
            
        </asp:SqlDataSource>




i want to filter StateDataSource with cmbCountryId Combo box value.

I did something like this... but not working
<SelectParameters>
                <asp:FormParameter FormField="cmbCountryId" Name="CountryMasterId"
                    Type="Int32" />
            </SelectParameters>



plzz help me
Posted

1 solution

Try with below code:
ASP.NET
<asp:DropDownList ID="DropDownListCountry" runat="server"
    Height="27px" Width="107px" DataSourceID="DS_Country"
    DataTextField="CountryName" DataValueField="CountryMasterId" AutoPostBack="True">
</asp:DropDownList>

<asp:SqlDataSource ID="DS_Country" runat="server" ConnectionString="Data Source=.;Initial Catalog=Db_ESmart;Integrated Security=True"
	ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CountryMasterId], [CountryName] FROM [CountryMaster] where IsDeleted=1 and IsActive=1">
</asp:SqlDataSource>
	
<asp:DropDownList ID="DropDownListState" runat="server"
    Height="20px" Width="110px"
    DataSourceID="DS_State" DataTextField="StateName" DataValueField="StateMasterId">
</asp:DropDownList>

<asp:SqlDataSource ID="DS_State" runat="server" ConnectionString="Data Source=.;Initial Catalog=Db_ESmart;Integrated Security=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [StateMasterId], [CountryMasterId], [StateName] FROM [StateMaster] 
WHERE ([CountryMasterId] = @CountryMasterId)">
    <SelectParameters>
        <asp:ControlParameter ControlID="DS_Country" PropertyName="SelectedValue"
            Name="CountryMasterId " Type="String" DefaultValue="2" />
    </SelectParameters>
</asp:SqlDataSource>


Here it used default value as "2" for parameter. You need to change as per your requirement.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900