<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>Searching for Items in a Database</title>
<link href="/shared/netdemos.css" rel="stylesheet" type="text/css">
<style type="text/css">
#msg {font-weight:bold; color:#055}
</style>
<script language="C#" runat="server" src="fetchData_oledb.cs" />
<script language="C#" runat="server">
int knt;
protected void Page_Load ( Object src, EventArgs E ) {
if ( IsPostBack ) {
string srchstring = Request.Params [ "strSearch" ];
string query = "SELECT Design, Model, Description, PlanID FROM Plans WHERE Model LIKE '%" +
srchstring + "%' OR Description LIKE '%" + srchstring + "%' ORDER BY Design, Model";
myGrid.DataSource = fetchData ( query, "plans" );
myGrid.DataBind ( );
knt = myGrid.Items.Count;
if ( knt > 0 ) {
msg.InnerText = "... " + knt + " home plans found where Model or Description contains '" + srchstring + "'";
myGrid.Visible = true;
}
else {
msg.InnerText = "Sorry, no match found. Please try again.";
myGrid.Visible = false;
}
vwSrc.Visible = myGrid.Visible;
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>ADO.NET Primer: <span class="hilite">Searching for Items in a Database</span></h2></div>
<div id="vwSrc" runat="server" visible=false><!-- #include virtual="~/shared/viewsrc_top.inc" --></div>
<hr size=1 width=92%>
<center>
<form runat="server">
<p>Search for <input id="strSearch" value="anything about house plans" runat="server"
onfocus="this.value=''">
<input type=submit value="Find" runat="server"></p>
<p><asp:requiredfieldvalidator
controltovalidate="strSearch"
display="dynamic" runat="server"><b>Nothing to search for. Please try again.</b>
</asp:requiredfieldvalidator></p>
<p id="msg" runat="server"></p>
<asp:datagrid id="myGrid" runat="server"
width=92% cellpadding=5 font-size="10pt"
gridlines="vertical"
headerstyle-backcolor="darkolivegreen"
headerstyle-forecolor="beige"
headerstyle-font-bold
itemstyle-verticalalign="top"
alternatingitemstyle-backcolor="whitesmoke"
autogeneratecolumns=false
maintainstate=false >
<columns>
<asp:templatecolumn>
<itemtemplate>
<img width=150 src='<%# Eval ( "PlanID", "/shared/images/plans/thumbs/{0}.jpg" ) %>'
title='<%# Eval ( "Model" ) %>'>
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn headertext="Design"
datafield="Design" />
<asp:boundcolumn headertext="Model"
datafield="Model" />
<asp:boundcolumn headertext="Description"
datafield="Description"
itemstyle-width=600 />
<asp:boundcolumn headertext="PlanID"
datafield="PlanID"
itemstyle-width=80 />
</columns>
</asp:datagrid>
</form>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>