asked on
<form id="form1" runat="server">
<div style="text-align:center">
<asp:Label ID="enterNamebutton" Text="<b>Enter Name</b>" runat="server" />
<asp:TextBox ID="txtSearch" runat="server" style="height:23px"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" TabIndex="1" height="27px" Text="GO" OnClick="btnSearch_Click" class="btn" />
<asp:Button ID="btnClear" OnClick="ClearFilter" height="27px" Text="Reset" runat="server" class="btn" />
</div>
<br /><br />
<div style="text-align:left">
<div style="text-align:center">SEARCH By Last Name, First Name (e.g.; Doe, John) and click the <div style="color:#69e">Go</div> button
Click the <div style="color:#69e;white-space:nowrap">Reset</div> button to SEARCH again<br /><br />
<asp:GridView ID="GridView1" BorderWidth="0" runat="server" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" PageSize="15" DataSourceID="APOMembers" EmptyDataText="No data found" Width="564px">
<HeaderStyle BackColor="#677617" ForeColor="White" Font-Size="Small" Font-Names="Verdana" width="100%" />
<RowStyle BackColor="White" Font-Size="Small" Font-Names="Verdana" BorderStyle="None" />
<AlternatingRowStyle BackColor="Gainsboro" width="100%" />
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton ID="lnkname" runat="server" Text='<%#Eval("Name") %>' PostBackUrl='<%#"~/Details.aspx?ID="&Eval("ID") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Cell_Phone" HeaderText="Cell Phone" SortExpression="Cell_Phone" >
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Phone" HeaderText="Home Phone" SortExpression="Phone" >
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Email_Add" HeaderText="Email Address" SortExpression="Email_Add" HtmlEncode="False">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="Members" runat="server" ConnectionString="<%$ ConnectionStrings:APOConnectionString %>"
ProviderName="<%$ ConnectionStrings:APOConnectionString.ProviderName %>"
SelectCommand="SELECT ID, ([firstName]&' '& [LastName]) as Name, [Cell_Phone], [Phone], [Email_Add] FROM Africa WHERE (firstName LIKE '' & @firstName & '%' OR lastname LIKE '' & @lastName & '%')">
<SelectParameters>
<asp:ControlParameter ControlID="txtSearch" Name="firstName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="txtSearch" Name="lastName" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
</form>
ASKER
ASKER
//Hotels.aspx
<%@ Page Language="C#" Debug="true" AutoEventWireup="false" Inherits="hotels" CodeFile="hotels.aspx.vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Available Hotels</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center">
<asp:Label ID="enterNamebutton" Text="<b>Enter Name</b>" runat="server" />
<asp:TextBox ID="SearchType" runat="server" style="height:23px"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" TabIndex="1" height="27px" Text="GO" OnClick="btnSearch_Click" class="btn" />
<asp:Button ID="btnClear" OnClick="ClearFilter" height="27px" Text="Reset" runat="server" class="btn" />
</div>
<br /><br />
<div style="text-align:left">
<div style="text-align:center">SEARCH By Name, and click the <div style="color:#69e">Go</div> button
Click the <div style="color:#69e;white-space:nowrap">Reset</div> button to SEARCH again<br /><br />
<asp:GridView ID="GridView1" BorderWidth="0" runat="server" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" PageSize="15" DataSourceID="Hotels" EmptyDataText="No data found" Width="564px">
<HeaderStyle BackColor="#677617" ForeColor="White" Font-Size="Small" Font-Names="Verdana" width="100%" />
<RowStyle BackColor="White" Font-Size="Small" Font-Names="Verdana" BorderStyle="None" />
<AlternatingRowStyle BackColor="Gainsboro" width="100%" />
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="name" >
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" >
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="Hotels" runat="server" ConnectionString="<%$ ConnectionStrings:HotesConnectionString %>"
ProviderName="<%$ ConnectionStrings:HotesConnectionString.ProviderName %>"
SelectCommand="SELECT Name,Type FROM Hotels WHERE (Name LIKE '' & @SearchType & '%')">
<SelectParameters>
<asp:ControlParameter ControlID="SearchType" Name="SearchType" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
</form>
</body>
</html>
//Hotels.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Hotels : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSearch_Click(object sender, EventArgs e)
{
GridView1.DataBind();
}
protected void ClearFilter(object sender, EventArgs e)
{
// remove the filter and rebind the grid
this.txtSearch.Text = string.Empty;
this.GridView1.DataBind();
}
}
//web.config: Add to your web.config or create yours
<connectionStrings>
<add name="HotesConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/inetpub/wwwroot/Hotels/App_Data/yourDB.mdb" providerName="System.Data.OleDb" />
</connectionStrings>
ASKER
ASKER
<asp:TextBox id="txtSearch" runat="server" />
strSQLQuery = "SELECT Name,Type FROM Hotels " _
& "FROM Hotels" _
& "WHERE city LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR country LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR [NUMBER OF ROOM] LIKE '%" & Replace(strSearch, "'", "''") & "%' " _ & "OR [NUMBER OF NIGHT] LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY city;"
<asp:TextBox id="txtSearch" runat="server" />
strSQLQuery = "SELECT Name,Type FROM Hotels " _
& "FROM Hotels" _
& "WHERE city LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR country LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR [NUMBER OF ROOM] LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "OR [NUMBER OF NIGHT] LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "ORDER BY city;"
<asp:TextBox id="SearchType" runat="server" />
query.CommandText = "SELECT Name,Type FROM Hotels " _
& "FROM Hotels" _
& "WHERE city LIKE ' " + Replace(SearchType, "'", "''") + "%' " _
& "OR country LIKE ' " + Replace(SearchType, "'", "''") + "%' " _
& "OR [NUMBER OF ROOM] LIKE ' " + Replace(SearchType, "'", "''") + "%' " _
& "OR [NUMBER OF NIGHT] LIKE '" + Replace(SearchType, "'", "''") + "%' " _
& "ORDER BY city;"
ASKER
Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.
TRUSTED BY
ASKER