<%@ 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> |