将选定的下拉列表值传递给参数

时间:2010-04-06 12:07:18

标签: asp.net

我有一个网格和下拉列表。我想通过选择下拉列表来过滤网格中的值。

我的代码就像这样

<asp:DropDownList ID="DDLVisitedVol" runat="server" AutoPostBack="true" DataSourceID="DsVisitedVol"
    DataTextField="VisitedVol" DataValueField="VisitedVol" 
    Width="244px">
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=""
    ProviderName=""
    SelectCommand="SELECT [ID],[UserName], [Email], [visitedVol] FROM [HitTracker] where visitedVol=@VisitedVol ">
    <SelectParameters>
        <asp:Parameter Name="VisitedVol" Type="String"/>
    </SelectParameters>
</asp:SqlDataSource>

如何将下拉列表的选定值传递给@VisitedVol?

2 个答案:

答案 0 :(得分:5)

使用ControlParameter:

<asp:ControlParameter ControlID="DDLVisitedVol" Name="VisitedVol" PropertyName="SelectedValue"  Type="String"/>

答案 1 :(得分:3)

ControlParameter是你的朋友:

<asp:ControlParameter Name="VisitedVol" ControlID="DDLVisitedVol" PropertyName="SelectedValue"/>