Address form Demo (VB.net) : Address form « Components « ASP.Net





Address form Demo (VB.net)

<%--
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 _
            ("StoresDB.mdb;"))
        DBCommand = New OleDbDataAdapter _
            ("Select Distinct State From Stores " _
            & "Order By State", DBConn)
        DBCommand.Fill(DSPageData, _
            "States")
        ddlStates.DataSource = _
            DSPageData.Tables("States").DefaultView
        ddlStates.DataBind()
    End If
End Sub
Sub ddlState_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 _
        ("StoresDB.mdb;"))
    DBCommand = New OleDbDataAdapter _
        ("Select Distinct City From Stores " _
        & "Where State = '" & ddlStates.SelectedItem.Text _
        & "' Order By City", DBConn)
    DBCommand.Fill(DSPageData, _
        "Cities")
    ddlCities.DataSource = _
        DSPageData.Tables("Cities").DefaultView
    ddlCities.DataBind()
    ddlCities.Visible = True
    lblMessage3.Visible = True
End Sub
Sub ddlCity_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 _
        ("StoresDB.mdb;"))
    DBCommand = New OleDbDataAdapter _
        ("Select StoreName as [Store Name], " _
        & "Address From Stores " _
        & "Where City = '" _
        & ddlCities.SelectedItem.Text & "' " _
        & "And State = '" _
        & ddlStates.SelectedItem.Text & "' " _
        & "Order By StoreName", DBConn)
    DBCommand.Fill(DSPageData, _
        "Stores")
    dgStores.DataSource = _
        DSPageData.Tables("Stores").DefaultView
    dgStores.DataBind()
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Store Location</TITLE>
</HEAD>
<Body LEFTMARGIN="40">
<form runat="server">
<BR><BR>
<asp:label 
    id="lblMessage2" 
    font-size="10pt"
    font-name="Lucida Console"
    text="Select a State"
    runat="server"
/>
<BR>
<asp:dropdownlist
    id="ddlStates"
    datatextfield="State" 
    autopostback="True"
    onselectedindexchanged="ddlState_Changed"
    runat="server"
/>
<BR><BR>
<asp:label 
    id="lblMessage3" 
    font-size="10pt"
    font-name="Lucida Console"
    text="Select a City"
    visible="False"
    runat="server"
/>
<BR>
<asp:dropdownlist
    id="ddlCities"
    datatextfield="City" 
    autopostback="True"
    onselectedindexchanged="ddlCity_Changed"
    visible="False"
    runat="server"
/>
<BR><BR>
<asp:label 
    id="lblMessage1" 
    font-size="12pt"
    font-bold="True"
    font-name="Lucida Console"
    text="Stores in Your Area"
    runat="server"
/>
<BR><BR>
<asp:datagrid
    id="dgStores" 
    runat="server" 
    autogeneratecolumns="True"
/>
</form>
</BODY>
</HTML>
           
       










StoresDB.zip( 8 k)

Related examples in the same category