本文介绍了如何过滤SqlDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个名为
的组合框
1)cmbCountryId
2)cmbStateId
我绑定这两个带有SQLDataSource的组合框
国家组合框
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希望用 cmbCountryId组合框值过滤 StateDataSource 。
我做了类似这样的事情。 ..但不工作
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帮帮我
plzz help me
推荐答案
<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>
此处参数的默认值为2。您需要根据您的要求进行更改。
Here it used default value as "2" for parameter. You need to change as per your requirement.
这篇关于如何过滤SqlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!