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 <appSettings> tag 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 Object, E As 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 Object, E As 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 Object, E As 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 developerWorks - FREE Tools! | Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
| | | | 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!
| | | | Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
| | | | 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!
| | | | This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
| | | | This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
| | | | Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
| | | | 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!
| | | | Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |