I'm new to both Visual Studio and ASP.NET.
I'm creating this project for my Data Base course in the university and I want to make it web-based with Visual Studio. So I've created my site, imported the DB, etc. and now I want to create a query with user input parameter. Using the query builder I've created the following SQL statement:
SELECT [Column1], [Column2], Column3
FROM [DataBaseTable]
WHERE ([Column1] = ?)
The next step in the query builder is where I need to define the parameter source. I figured out that I need a control source, using a DropDownList. I've created the list items and assigned the list to the parameter via the control option.
So, now when I launch my site the query is working, getting the value from the first list item. The problem is that I want to change the query value dynamically by choosing a different list item. What do I need to do to make it so?
EDIT: This is the code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" Height="269px" Width="923px">
<Columns>
<asp:BoundField DataField="Column1" HeaderText="Column1" SortExpression="Column1" />
<asp:BoundField DataField="Column2" HeaderText="Column2" SortExpression="Column2" />
<asp:BoundField DataField="Column3" HeaderText="Column3" SortExpression="Column3" />
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Road.accdb" SelectCommand="SELECT [Column1], [Column2], [Column3] FROM [Второкласни пътища] WHERE ([Column1] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" DefaultValue="" Name="?" PropertyName="SelectedValue" />
</SelectParameters>
</asp:AccessDataSource>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
Based on your code, I think you may only need one small change. Add "AutoPostBack="true" to your DDL. I would also give your ListItems explicit values, to be more clear. This way you can set the ListItem text to something useful (whatever the number is supposed to represent in your DB).
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList>