<%--
Code revised from
ASP.NET Tips & Techniques (Paperback)
by Greg Buczek
# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149
--%>
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
If Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("PhoneDir.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select EmpName as [Employee Name], " _
& "Department, PhoneNumber as " _
& "[Phone Number] From Emps " _
& "Order By EmpName", DBConn)
DBCommand.Fill(DSPageData, _
"Employees")
dgEmps.DataSource = _
DSPageData.Tables("Employees").DefaultView
dgEmps.DataBind()
DBCommand = New OleDbDataAdapter _
("Select Distinct Department From Emps " _
& "Order By Department", DBConn)
DBCommand.Fill(DSPageData, _
"Departments")
ddlDepartments.DataSource = _
DSPageData.Tables("Departments").DefaultView
ddlDepartments.DataBind()
End If
End Sub
Sub ddl1_Changed(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath _
("PhoneDir.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select EmpName as [Employee Name], " _
& "Department, PhoneNumber as " _
& "[Phone Number] From Emps " _
& "Where Department = '" _
& ddlDepartments.SelectedItem.Text _
& "' Order By EmpName", DBConn)
DBCommand.Fill(DSPageData, _
"Employees")
dgEmps.DataSource = _
DSPageData.Tables("Employees").DefaultView
dgEmps.DataBind()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Phone Directory</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label
id="lblMessage1"
font-size="12pt"
font-bold="True"
font-name="Lucida Console"
text="Phone Number List"
runat="server"
/>
<BR><BR>
<asp:datagrid
id="dgEmps"
runat="server"
autogeneratecolumns="True"
/>
<BR><BR>
<asp:label
id="lblMessage2"
font-size="10pt"
font-name="Lucida Console"
text="Filter by Department"
runat="server"
/>
<BR>
<asp:dropdownlist
id="ddlDepartments"
datatextfield="Department"
autopostback="True"
onselectedindexchanged="ddl1_Changed"
runat="server"
/>
</form>
</BODY>
</HTML>
|