Need some help getting drop downs populated in aspx

liunx

Guest
I am making some 3 dropdownlists. each one is populated based on the previous ones selected value. Im kinda new to asp.net and could really use a little help.
All queries are from a table called PaperArchive
the drop downs are regiodd then the second is yeardd (havent got to the third yet)

the firt drop down (regiondd) works fine.
when i choose an item (say new york) i want to have the yeardd drop down populate with years that the region column = new york

i get an error saying
" System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'Region = New York' "

but thats what i want "where region = new york". I dont get it

heres my code


<script runat="server">
dim mycommand as OleDbDataAdapter
dim SQL as String
dim ds as New DataSet
dim myconnection as OleDbConnection
dim OleDBserver as String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=***"

Sub Page_Load(myList as Object, e as EventArgs)
If NOT Page.IsPostBack()
SQL = "Select Distinct Region from PaperArchive"
myconnection = new OleDbConnection(OleDBserver)
mycommand = new OleDbDataAdapter(SQL,myconnection)
mycommand.Fill(ds, "PaperArchive")
regiondd.DataSource = ds.Tables("PaperArchive").DefaultView
regiondd.DataBind()
regiondd.Items.Insert(0,"")
End If
End Sub

Sub YearBox(Sender AS Object, E AS EventArgs)
If regiondd.SelectedItem.Value <> "" then
SQL = "Select xYear from PaperArchive Where Region = "
SQL += regiondd.SelectedItem.Value
myconnection = new OleDbConnection(OleDBserver)
mycommand = new OleDbDataAdapter(SQL,myconnection)
mycommand.Fill(ds, "PaperArchive")
yeardd.DataSource = ds.Tables("PaperArchive").DefaultView
yeardd.DataBind()
yeardd.Items.Insert(0,"")
End If
'monthdd.DataSource = ""
'monthdd.DataBind()
End Sub
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form RUNAT="server">
Select Region:
<asp:DropDownList
AutoPostBack="true"
DataTextField="Region"
DataValueField="Region"
ID="regiondd"
runat="server"
onSelectedIndexChanged = "YearBox" />

<asp:DropDownList
AutoPostBack="true"
DataTextField="xYear"
DataValueField="xYear"
ID="yeardd"
runat="server" />
</form>you need quotes around 'New York'Like this:


If regiondd.SelectedItem.Value <> "" then
SQL = "Select xYear from PaperArchive Where Region = '" & regiondd.SelectedItem.Value & "'"
myconnection = new OleDbConnection(OleDBserver)
mycommand = new OleDbDataAdapter(SQL,myconnection)
mycommand.Fill(ds, "PaperArchive")
yeardd.DataSource = ds.Tables("PaperArchive").DefaultView
yeardd.DataBind()
yeardd.Items.Insert(0,"")
End IfHi guys!

I created a control that works like an AJAX container. Basically the way it works is that all the ASP.NET controls that you place inside of the AJAX container will automatically become AJAX enabled.

For example, if you need to create a web form with three dropdownlists and you want the picked value of one DDL affects the items in the others DDLs (like in an auto dealer website) all you need to do is make sure you move these three dropdownlists into this AJAX container control. The way you code and setup the three dropdownlists remains exactly the same. The container control injects the necessary AJAX functions.

I uploaded this control and posted some walkthrough tutorials at <!-- m --><a class="postlink" href="http://www.KYNOU.com">http://www.KYNOU.com</a><!-- m -->

Check it out!
 
Back
Top