Pass the selected value of the drop-down list to the parameter

I have a grid and a drop down list. I want to filter the values ​​in a grid by selecting a dropdown.

My code is

<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 to pass the selected dropdown value to @VisitedVol?

+4
source share
3 answers

Use ControlParameter:

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

ControlParameter is your friend:

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

You must handle the ddl selectedIndexChanged event and re-bind the data after filtering by the value of the selected ddl element.

-2
source

Source: https://habr.com/ru/post/1306118/


All Articles