ASP Code
  Home arrow ASP Code arrow Relational DropDownList Using VB.NET
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Relational DropDownList Using VB.NET
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 107
    2003-07-16

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Relational DropDownList Using VB.NET Code Example. In this code, we illustrate three steps:
    Step 1. Copy and paste the code below on to the newly created aspx file
    Step 2. Add <appSettings> tag to the existing web.config
    Step 3. Make sure you have Northwind database install in your system******************************

     <!-- ASPX Page --><!-- Step 1. Copy and paste the code below on to the newly created aspx file --><!-- Step 2. Add <appSettingstag to the existing web.config --><!-- Step 3. Make sure you have Northwind database install in your system --><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %>
    <
    SCRIPT language=VB runat="server">

    Public 
    Sub Page_Load(Source As ObjectAs EventArgs)

    If 
    Not IsPostBack Then

    Dim _Conn 
    As SqlConnection
    Dim _Command 
    As SqlCommand
    Dim _Reader 
    As SqlDataReader
    Dim SQL 
    As String

    SQL 
    "select * from Region"

    _Conn GetConnection()

    _Command = new SqlCommand(SQL_Conn)

    _Reader _Command.ExecuteReader()

    Regions.Items.Add(new ListItem("Select Region...""0")) 

    While 
    _Reader.Read()
    Regions.Items.Add(new ListItem(_Reader("RegionDescription").ToString(), _Reader("RegionID").ToString()))
    End While

    Territory.Items.Add(new ListItem("Select Territory...""0"))

    End If

    End Sub

    Function GetConnection() As SqlConnection
    Dim _Connection 
    As SqlConnection
    Dim ConnStr 
    As String

    ConnStr 
    ConfigurationSettings.AppSettings("ConnectionString")

    _Connection = new SqlConnection(ConnStr)
    _Connection.Open()

    Return 
    _Connection
    End 
    Function 


    Sub OnSelectedRegionIndexChanged(Source As ObjectAs EventArgs)
    Dim _Region As Integer

    _Region 
    Regions.SelectedItem.Value

    If _Region 0 Then 

    Dim _Conn 
    As SqlConnection
    Dim _Command 
    As SqlCommand
    Dim _Reader 
    As SqlDataReader
    Dim SQL 
    As String

    SQL 
    "select * from Territories where RegionID ='" _Region "'"

    _Conn GetConnection()

    _Command = new SqlCommand(SQL_Conn)

    _Reader _Command.ExecuteReader()

    Territory.Items.Clear()
    Territory.Items.Add(new ListItem("Select Territory...""0"))


    While 
    _Reader.Read()
    Territory.Items.Add(new ListItem(_Reader("TerritoryDescription").ToString(), _Reader("TerritoryID").ToString()))
    End While

    txtRegion.Text Regions.SelectedItem.Text 
    txtTerritory
    .Text "" 
    Else

    Territory.Items.Clear()
    Territory.Items.Add(new ListItem("Select Territory...""0"))
    txtRegion.Text ""
    txtTerritory.Text ""

    End If 

    End Sub

    Sub OnSelectedTerritoryIndexChanged
    (Source As ObjectAs EventArgs)

    Dim _Territory As Integer

    _Territory 
    Territory.SelectedItem.Value

    If _Territory 0 Then

    txtTerritory
    .Text Territory.SelectedItem.Text
    Else
    txtTerritory.Text ""
    End If

    End Sub

    </SCRIPT>

    <FORM runat="server"><asp:DropDownList id=Regions runat="server" 
    OnSelectedIndexChanged="OnSelectedRegionIndexChanged" 
    AutoPostBack="True"></asp:DropDownList>
    <asp:DropDownList id=Territory runat="server" 
    OnSelectedIndexChanged="OnSelectedTerritoryIndexChanged" 
    AutoPostBack="True"></asp:DropDownList>
    <asp:Label id=txtRegion runat="server"></asp:Label>
    <asp:Label 
    id=txtTerritory 
    runat="server"></asp:Label></FORM><!-- Web.Config --><CONFIGURATION><APPSETTINGS><ADD 
    value="Server=(local)NetSDK;uid=sa;pwd=;database=Northwind" 
    key="ConnectionString" /></APPSETTINGS></CONFIGURATION>


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process.
    FREE! Go There Now!


    NEW! Application Development Tools for the Mainframe Developer

    You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Develop with Java and PHP technology on AIX Version 5.3, Part 6: Building the Java business application

    Set up a PHP Web interface for the Java(TM) business application using a database created in earlier in this series. The PHP Web interface collects information from users and sends the session data to the Java business application for processing and for a response.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Kick-start your Java apps

    To create, test, and deploy a Web-based application or Web service rapidly, you need a proven relational database, a standards-compliant Web application server, and a flexible IDE. Ideally, all these software packages are production-tested, simple to obtain, easy to use, and well integrated with one another. This tutorial shows you how to use IBM-backed open source and free software to kick-start your Java Web-based application development. You'll learn exactly where to download such components, install them, and get them working for you today.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! The IBM DB2 Detective Game

    Here's a fun way to learn about DB2! Learn or teach the basics of DB2 and relational database with an interactive game called The DB2 Detective Game. The game teaches relational database concepts and shows how technology can be applied to solving real-life problems (the game's theme is a crime investigation). This tutorial has been updated for DB2 9.
    FREE! Go There Now!


    NEW! Travels with Mark: A Hitchhiker&apos;s Guide to the UniVerse, Part 5: Increase dynamic array processing performance in IBM UniVerse

    Investigate the effects of field-level caching in dynamic array access, in part 5 of the UniVerse performance series.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway