Home
About
Contact
Categories
Classic ASP (28 - Sub-Categories)
CSS (1 - Sub-Category)
JavaScript (4 - Sub-Categories)
Databases (22 - Sub-Categories)
ASP.NET (23 - Sub-Categories)
Delphi (5 - Sub-Categories)
Windows Server Core (3 - Sub-Categories)
VMWare (1 - Sub-Category)
Code Editing Tools (2 - Sub-Categories)
Linux (2 - Sub-Categories)
Dell Servers (15 - Sub-Categories)
Bug Reports
(Bugs Fixed
New CFFCS Coding Source is still in Beta
Please report any errors to the [Contact] page. Thank you.
Classic ASP (28)
CSS (1)
JavaScript (4)
Databases (22)
ASP.NET (23)
Delphi (5)
Windows Server Core (3)
VMWare (1)
Code Editing Tools (2)
Linux (2)
Dell Servers (15)
Resources
[View The Source Code For This Project]
Format SQL Script
ASP.NET
VB.NET
ASP.NET (VB) Fill select menu with records from a database, insert selected records with live updated data
HTML
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Load.aspx.vb" Inherits="Load" %> <% Dim getMyID As String = Request.QueryString("MyID") %>
<%if getMyID="" then%>
Load ID
to proceed <%elseif getMyID<>"" then%>
ASP.NET (VB Version) SQL Server Database Driven Dropdown Menu
This demonstration loads all values into a Select Menu from a database table.
" />
<% End If %>
JavaScript
ajaxsbmt
$(document).ready(function(){ $('form').change(function(e){ e.preventDefault(); $.ajax({ url: "Update.ashx", type: "POST", data: $(this).serialize(), success: function(data){ $(".postData").html(data); }, error: function(){ $(".postData").html("Form submission failed!"); } }); }); });
SQL
DropDown
-- Create a new database called [Virtual-Class-01] in SQL Server. -- Right-click and choose [New Query] -- Copy and paste the code below and hit [Execute] USE [Virtual-Class-01] GO /****** Object: Table [dbo].[DropDown] Script Date: 8/4/2022 10:40:41 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[DropDown]( [ddID] [int] IDENTITY(1,1) NOT NULL, [ddName] [nvarchar](50) NOT NULL, CONSTRAINT [PK_DropDown] PRIMARY KEY CLUSTERED ( [ddID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[Dropdown2] Script Date: 8/4/2022 10:40:41 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Dropdown2]( [InsertID] [int] IDENTITY(1,1) NOT NULL, [MyID] [int] NOT NULL, [ddid] [int] NOT NULL, CONSTRAINT [PK_Dropdown2] PRIMARY KEY CLUSTERED ( [InsertID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO SET IDENTITY_INSERT [dbo].[DropDown] ON GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (1, N'asp classic') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (2, N'visual basic') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (3, N'jquery') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (4, N'javascript') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (5, N'asp.net') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (6, N'vb.net') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (7, N'C#') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (8, N'web.config') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (9, N'database.config') GO INSERT [dbo].[DropDown] ([ddID], [ddName]) VALUES (10, N'runtime') GO SET IDENTITY_INSERT [dbo].[DropDown] OFF GO
ASP.NET
web.config
database.config
Imports
Page_Load
ashx-Imports
ashx-ProcessRequest
ashx-ashx-update-Imports
ashx-update-ProcessRequest
Imports System.Data Imports System.Configuration Imports System.Data.SqlClient
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim cn As String = ConfigurationManager.ConnectionStrings("Virtual-Learning").ConnectionString Using con As New SqlConnection(cn) Using cmd As New SqlCommand("SELECT ddId, ddName FROM Dropdown") cmd.CommandType = CommandType.Text cmd.Connection = con con.Open() DropDownList1.DataSource = cmd.ExecuteReader() DropDownList1.DataTextField = "ddName" DropDownList1.DataValueField = "ddId" DropDownList1.DataBind() con.Close() End Using End Using DropDownList1.Items.Insert(0, New ListItem("--Select Programming Language--", "0")) End If End Sub
Imports System Imports System.Web Imports System.Data Imports System.Configuration Imports System.Data.SqlClient
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim getID As String = context.Request.Form("DropDownList1") Dim getMyID As String = context.Request.QueryString("MyID") 'context.Response.Write(getMyID & "-" & getID) 'context.Response.End() Dim strSQL As String Dim objCmd As SqlCommand = Nothing Dim LessonCon As New SqlConnection LessonCon = New SqlConnection(ConfigurationManager.ConnectionStrings("Virtual-Learning").ConnectionString) LessonCon.Open() Dim getDD As New SqlCommand("SELECT DropDown.ddID, Dropdown2.MyID, Dropdown.ddName FROM DropDown INNER JOIN Dropdown2 ON DropDown.ddID = Dropdown2.ddid WHERE Dropdown2.MyID = @MyID", LessonCon) getDD.Parameters.Add(New SqlParameter("@MyID", getMyID)) Dim rsDD As SqlDataReader rsDD = getDD.ExecuteReader() While rsDD.Read() context.Response.Write(rsDD("ddID") & "-" & rsDD("ddName") & "
") 'If rsDD.Read() Then ' context.Response.Write(rsDD("ddID") & "-" & rsDD("ddName") & "
") 'Else ' context.Response.Write("No records exist at this moment. Please choose one to begin.") 'End If End While rsDD.Close() LessonCon.Close() End Sub
Imports System Imports System.Web Imports System.Data Imports System.Configuration Imports System.Data.SqlClient
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim getID As String = context.Request.Form("DropDownList1") Dim getMyID As String = context.Request.Form("MyID") 'context.Response.Write(getMyID & "-" & getID) 'context.Response.End() Dim strSQL As String Dim objCmd As SqlCommand = Nothing Dim cn As New SqlConnection cn = New SqlConnection(ConfigurationManager.ConnectionStrings("Virtual-Learning").ConnectionString) cn.Open() Dim getDD As New SqlCommand("SELECT DropDown.ddID, Dropdown2.MyID FROM DropDown INNER JOIN Dropdown2 ON DropDown.ddID = Dropdown2.ddid WHERE DropDown.ddID = @ddID AND Dropdown2.MyID = @MyID", cn) getDD.Parameters.Add(New SqlParameter("@ddID", getID)) getDD.Parameters.Add(New SqlParameter("@MyID", getMyID)) Dim rsDD As SqlDataReader rsDD = getDD.ExecuteReader() If rsDD.Read() Then context.Response.Write("The record already exists, please choose another one.") Else strSQL = "insert into Dropdown2 (ddid, MyID)values(@ddid, @MyID)" objCmd = New SqlCommand(strSQL, cn) objCmd.Parameters.Add(New SqlParameter("@ddid", getID)) objCmd.Parameters.Add(New SqlParameter("@MyID", getMyID)) objCmd.ExecuteNonQuery() context.Response.Write("Recorded inserted Successfully!") End If rsDD.Close() LessonCon.Close() End Sub
Preview
Tags
ASP.NET VB code loads records from a database into a select menu
live JQuery view of the data