Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing the selected value of a dropdownlist to a parameter

Tags:

asp.net

I have a grid and dropdownlist. I want to filter values in a grid by the selection of the dropdownlist.

My code is like this

<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>

How can I pass the selected value of the dropdownlist to @VisitedVol?

like image 445
Nandini Avatar asked Feb 28 '23 06:02

Nandini


2 Answers

Use ControlParameter:

<asp:ControlParameter ControlID="DDLVisitedVol" Name="VisitedVol" PropertyName="SelectedValue"  Type="String"/>
like image 74
Nix Avatar answered May 09 '23 19:05

Nix


The ControlParameter is your friend:

<asp:ControlParameter Name="VisitedVol" ControlID="DDLVisitedVol" PropertyName="SelectedValue"/>
like image 38
richeym Avatar answered May 09 '23 20:05

richeym