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!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Develop Systems Software Assets with IBM Rational Asset Manager

    Join us for this on demand webcast to learn about developing complex systems more quickly and efficiently. We'll cover market drivers for developing, governing and reusing systems software assets and how you can develop system software assets with Rational Asset Manager.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Rational Talks to You:Per Kroll on Rational Method Composer Plug-in customization

    Join this Rational Talks to You teleconference on December 11 at 1:00 pm ET to get tips on building your own plugins with Rational Method Composer. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    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 Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    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 2 Hosted by Hostway
    Stay green...Green IT