1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Search Queries in ASP/VB.net Help Required!

Discussion in 'C#' started by j4v3d, Apr 6, 2011.

  1. #1
    hi

    im trying to perform a search query using drop down boxes with a button named search. I want it to bring up the data that is searched for. I dont know where to start from, i have looked around for some coding and different ways to do it but they seem complicated, this is the bit of ASP that is my weakness, need some assistance and guidance. below is the code for the page;

    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ForSale.aspx.vb" Inherits="Users_ForSale" title="Properties For Sale" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
        </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
            
            <h3>Properties For Sale</h3>
            <h5>
                <asp:Label ID="lblTown" runat="server" Text="Town:"></asp:Label>
                <asp:DropDownList ID="ddlTownSearch" runat="server">
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem>Chadderton</asp:ListItem>
                    <asp:ListItem Value="Failsworth"></asp:ListItem>
                    <asp:ListItem>Oldham</asp:ListItem>
                    <asp:ListItem>Royton</asp:ListItem>
                    <asp:ListItem>Shaw</asp:ListItem>
                </asp:DropDownList>
                <asp:Label ID="lblBedroomsSearch" runat="server" Text="Bedrooms:"></asp:Label>
                <asp:DropDownList ID="DropDownList1" runat="server">
                    <asp:ListItem></asp:ListItem>
                    <asp:ListItem>1</asp:ListItem>
                    <asp:ListItem Value="2"></asp:ListItem>
                    <asp:ListItem Value="3"></asp:ListItem>
                    <asp:ListItem>4</asp:ListItem>
                    <asp:ListItem>5</asp:ListItem>
                    <asp:ListItem>6+</asp:ListItem>
                </asp:DropDownList>
                <asp:Label ID="lblMinPrice" runat="server" Text="Min Price (£):"></asp:Label>
                <asp:TextBox ID="txtMinPriceSearch" runat="server" Width="87px"></asp:TextBox>
                <asp:Label ID="lblMaxPriceSearch" runat="server" style="text-align: left" 
                    Text="Max Price (£):"></asp:Label>
                <asp:TextBox ID="TextBox1" runat="server" Width="87px"></asp:TextBox>
            </h5>
            <h5>
                <asp:Button ID="btnForsaleSearch" runat="server" Text="Search" Height="26px" />
            </h5>
            <p>
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                    AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
                    DataKeyNames="ProductId" DataSourceID="SqlDataSource1" ForeColor="#333333" 
                    GridLines="None" Width="588px">
                    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                    <Columns>
                        <asp:ImageField DataImageUrlField="ImageURL">
                        </asp:ImageField>
                        <asp:BoundField DataField="ProductId" HeaderText="ProductId" ReadOnly="True" 
                            SortExpression="ProductId" />
                        <asp:BoundField DataField="Description" HeaderText="Description" 
                            SortExpression="Description" />
                        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                        <asp:BoundField DataField="Town" HeaderText="Town" 
                            SortExpression="Town" />
                    </Columns>
                    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
            </p>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:JPEstatesConnectionString %>" 
            SelectCommand="SELECT * FROM [Products]" 
                DeleteCommand="DELETE FROM [Products] WHERE [ProductId] = @ProductId" 
                InsertCommand="INSERT INTO [Products] ([ProductId], [Description], [Price], [Category], [ImageURL]) VALUES (@ProductId, @Description, @Price, @Category, @ImageURL)" 
                UpdateCommand="UPDATE [Products] SET [Description] = @Description, [Price] = @Price, [Category] = @Category, [ImageURL] = @ImageURL WHERE [ProductId] = @ProductId">
                    <DeleteParameters>
                        <asp:Parameter Name="ProductId" Type="String" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Price" Type="Decimal" />
                        <asp:Parameter Name="Category" Type="String" />
                        <asp:Parameter Name="ImageURL" Type="String" />
                        <asp:Parameter Name="ProductId" Type="String" />
                    </UpdateParameters>
                    <InsertParameters>
                        <asp:Parameter Name="ProductId" Type="String" />
                        <asp:Parameter Name="Description" Type="String" />
                        <asp:Parameter Name="Price" Type="Decimal" />
                        <asp:Parameter Name="Category" Type="String" />
                        <asp:Parameter Name="ImageURL" Type="String" />
                    </InsertParameters>
            </asp:SqlDataSource>
    
    </asp:Content>
    Code (markup):

    SEMrush
     
    j4v3d, Apr 6, 2011 IP
    SEMrush
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,681
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your using labels but not associating the control to them so adding overhead without the benefits.... that a side:

    One of the options is to create a onclick event in your code behind to run when the button is pressed, change the select parameter using the inputs and rebind the results to the GridView
     
    AstarothSolutions, Apr 6, 2011 IP
  3. j4v3d

    j4v3d Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    is it possible you can show me an example?

    what is the easiest way to create a search and display the results in the gridview?
     
    j4v3d, Apr 6, 2011 IP
  4. j4v3d

    j4v3d Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    can i like use a LINQ view whatever it is called in ASP? to create like a search facility?
     
    j4v3d, Apr 7, 2011 IP