ASP Code
  Home arrow ASP Code arrow Relational DropDownList Using VB.NET
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 114
    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
     
     
    ADVERTISEMENT


    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!


    NEW! Best Practices in Integrated Requirements Management

    Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right."
    FREE! Go There Now!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! Evaluate Rational Host Access Transformation Services (HATS) Toolkit V7.1

    Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications.
    FREE! Go There Now!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    Refresh! IBM Rational Systems Development Solution eKit

    With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
    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-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek