View Single Post
Old 01-04-2013, 01:44 PM   PM User | #1
Zarathas
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Zarathas is an unknown quantity at this point
Database Search Page

Hi All

I am attempting to create a web page using Visual Studio to search the "products" table in my local SQL Database. I have used a Gridview control to display the results from four drop down menus which are price, brand, colour and screen size.

Ive managed to make the brand and colour menus to work, affecting the results of the Gridview, but I cannot make the others work because they involve a number range e.g. 200-500, 500-1000 etc... I am not sure what code I will need to make this work. Here is what ive done so far,

Code:
<%@ Page MasterPageFile="~/MasterPage.Master" Language="vb" AutoEventWireup="false" CodeBehind="products.aspx.vb" Inherits="webproject.products" %>
<asp:Content ID="Content1" runat="server" 
    contentplaceholderid="ContentPlaceHolder1">
    <p>
        <strong __designer:mapid="29">Search Products</strong><br 
            __designer:mapid="26" />
        <br __designer:mapid="28" />
        <asp:Label ID="Label1" runat="server" Text="Price: "></asp:Label>
        <asp:DropDownList ID="PriceDropDown" runat="server" AutoPostBack="True">
            <asp:ListItem Value="">Under £200</asp:ListItem>
            <asp:ListItem Value="">£200-500</asp:ListItem>
            <asp:ListItem Value="500-1000">£500-1000</asp:ListItem>
            <asp:ListItem Value="1000-1500">£1000-1500</asp:ListItem>
            <asp:ListItem Value="1500-100000">Over £1500 </asp:ListItem>
        </asp:DropDownList>
        <br __designer:mapid="2a" />
        <br __designer:mapid="2b" />
        <asp:Label ID="Label2" runat="server" Text="Brand: "></asp:Label>
        <asp:DropDownList ID="BrandDropDown" runat="server" 
            Width="80px" AutoPostBack="True">
            <asp:ListItem Value="Samsung">Samsung</asp:ListItem>
            <asp:ListItem Value="LG">LG</asp:ListItem>
        </asp:DropDownList>
        <br __designer:mapid="30" />
        <br __designer:mapid="31" />
        <asp:Label ID="Label3" runat="server" Text="Screen Size: "></asp:Label>
        <asp:DropDownList ID="ScreenDropDown" runat="server" 
            Width="80px" AutoPostBack="True">
            <asp:ListItem Value="ScreenSize &gt;= 32 &lt;=39">From 32&quot; to 39&quot;</asp:ListItem>
            <asp:ListItem Value="ScreenSize &gt;=40 &lt;=45">From 40&quot; to 45&quot;</asp:ListItem>
            <asp:ListItem Value="ScreenSize &gt;=46 &lt;=55">From 46&quot; to 55&quot;</asp:ListItem>
            <asp:ListItem Value="ScreenSize &gt;=56">56&quot; and More</asp:ListItem>
        </asp:DropDownList>
        <br __designer:mapid="36" />
        <br __designer:mapid="37" />
        <asp:Label ID="Label4" runat="server" Text="Colour: "></asp:Label>
        <asp:DropDownList ID="ColourDropDown" runat="server" 
            Width="80px" AutoPostBack="True">
            <asp:ListItem Value="Black">Black</asp:ListItem>
            <asp:ListItem Value="Silver">Silver</asp:ListItem>
        </asp:DropDownList>
    </p>
    <p>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" EnableModelValidation="True">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
                <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                <asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
                <asp:BoundField DataField="ScreenSize" HeaderText="ScreenSize" 
                    SortExpression="ScreenSize" />
                <asp:BoundField DataField="Colour" HeaderText="Colour" 
                    SortExpression="Colour" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT * FROM [Products] WHERE (([Brand] = @Brand) AND ([Colour] = @Colour) ([Price] ))">
            <SelectParameters>
                <asp:ControlParameter ControlID="BrandDropDown" Name="Brand" 
                    PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="ColourDropDown" Name="Colour" 
                    PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="PriceDropDown" Name="Price" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    </p>
</asp:Content>
If anyone can help it would be much appreciated Also sorry if this is in the wrong section, i'm a bit new to all of this.
Zarathas is offline   Reply With Quote