Automatically Submit an Page using ASP.NET DropDownList Box

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 10
January 01, 2002
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Automatically Submit an Page
using ASP.NET DropDownList Box

This example shows how to populate a dropdownlist box from a database andhave it automatically submit the page when selected. This specific example does aselect against a Pubs database and write out a message it was selected with a timestamp. This example requires MSDE or SQL Server with the pub's database to loaded.

Here is the code

<%@ Page EnableSessionState="False" EnableViewState="True" Debug="False" Trace="False" strict="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<script language=VB runat=server>
Sub Page_Load(Sender As Object, E As EventArgs)
If Not IsPostBack Then
Dim myConnection As SqlConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
Dim mySQL as string = "Select au_id, au_lname, au_fname from Authors"
Dim myCmd as New SQLCommand(mySQL,myConnection)
myConnection.Open()
MyDropDownList.DataSource = myCmd.ExecuteReader()
myDropDownList.DataBind()
myConnection.Close()
End If
End Sub

Sub Index_Changed(sender As Object, e As EventArgs)
lblDisplayMessage.Text = "Form Was Submitted Automatically on Selection of DropDown: " & DateTime.Now.ToString()
End Sub
</script>
<html>
<head><title>View Specific Profession Info</title></head>
<body>
<asp:label id="lblDisplayMessage" runat="server" />
<form name="frmValues" runat="server">
<asp:dropdownlist
DataValueField = "au_lname"
DataTextField = "au_id"
id="MyDropDownList"
OnSelectedIndexChanged="Index_Changed"
autopostback="true"
runat="server" />
</form>
</body>
</html>
blog comments powered by Disqus
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...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials