|
xxx
Searcher Example using
EasyListBox
by Peter Brunone
This example improves upon the standard city/state/zip search script shown
here.
Notice there is not a single line of VB code to make the listboxes work.
The ConnectionStringAccess property is set to "biblio", which is the name of a key in the web.config file.
An explicit connection string can also be used.
filename=/experiments/easylistbox/searcherDependent.aspx
<%@ Register TagPrefix="ELB" Namespace="ELB" Assembly="EasyListBox" %>
<%@ import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
Dim strConn As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("/experiments/data/biblio.mdb") & ";"
Sub Page_Load(Src As Object, E As EventArgs)
searchagain.Visible = False
End Sub
Sub Search_click(s As Object, e As EventArgs)
Trace.Write("city",cy.SelectedText)
Trace.Write("state",st.SelectedText)
Trace.Write("zip",zp.SelectedText)
Dim strSQL As String
Dim prefix As String
searchcriteria.Visible = False
search.Visible = False
searchagain.Visible = True
searchresults.Visible = True
strSQL="select * from publishers where "
If cy.SelectedText.Trim = "" And st.SelectedText.Trim = "" And zp.SelectedText.Trim = "" Then
message.text="You did not choose any search categories so we cannot Search"
searchresults.Visible=false
exit sub
Else
message.text=""
End If
If cy.SelectedText.Trim <> "" Then
strSQL=strSQL & " city='" & cy.SelectedText & "' "
prefix=" AND "
End If
If st.SelectedText.Trim <> "" Then
strSQL=strSQL & prefix & " state='" & st.SelectedText & "' "
prefix=" AND "
End If
If zp.SelectedText.Trim <> "" Then
strSQL=strSQL & prefix & " zip='" & zp.SelectedText & "' "
End If
trace.write("strSQL",strSQL)
Dim Conn as New OLEDBConnection(strConn)
Dim Cmd as New OLEDBCommand(strSQL,Conn)
Conn.Open()
searchresults.DataSource = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
searchresults.DataBind()
Conn.Close()
End Sub
Sub Searchagain_click(s As Object, e As EventArgs)
searchcriteria.Visible = True
searchresults.Visible = False
searchagain.Visible = False
search.Visible = True
End Sub
</script>
<html><head>
<title>Searcher</title>
</head>
<body bgcolor="#FFFFFF">
<form runat="server">
<asp:literal id="message" runat="server"/>
<asp:Table id="searchcriteria" runat="server" GridLines="both" BorderWidth="1px">
<asp:TableRow>
<asp:TableCell>State</asp:TableCell>
<asp:TableCell valign="top">
<ELB:EasyListBox id="st" Runat="Server" EnableViewState="false" Height="100px"
SelectQuery="select distinct state from publishers where state is not null order by state"
ChildListName="cy" ConnectionStringAccess="biblio"
DataTextField="state" DataValueField="state"
/>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>City</asp:TableCell>
<asp:TableCell valign="top">
<ELB:EasyListBox id="cy" runat="server" EnableViewState="false" Height="100px"
SelectQuery="select distinct state, city from publishers where state is not null order by city"
ParentList="st" ChildListName="zp" ConnectionStringAccess="biblio"
DataTextField="city" DataValueField="city" DataFilterField="state"
/>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Zip</asp:TableCell>
<asp:TableCell valign="top">
<ELB:EasyListBox id="zp" runat="server" EnableViewState="false" Height="100px"
SelectQuery="select distinct city, zip from publishers order by zip"
ParentList="cy" ConnectionStringAccess="biblio"
DataTextField="zip" DataValueField="zip" DataFilterField="city"
/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:button id="search" text="search for data" onclick="search_click" runat="server"/><br>
<asp:button id="searchagain" text="search for data again" onclick="searchagain_click" runat="server"/>
<ASP:DataGrid id="searchresults" runat="server"
Width="100%"
BackColor="white"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
Headerstyle-BackColor="lightblue"
Headerstyle-Font-Size="10pt"
Headerstyle-Font-Style="bold"
MaintainState="false"
/>
</form>
</body></html>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|