By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Listbox w/o Autopostback

P: n/a
HI,

I need to populate 2 listboxes from a db. When the page loads then the
first listbox needs to be populated and based on selection from that
listbox the second listbox needs to be populated accordingly with the
matching items.
However, my boss doesn't want the page to do a postback once an item
from the first listbox is selected. also, he doesn't want to use
ado.net but classic ado.
He wants to use jscript. I am writing my code in vb.net

I wrote a code but only the first listbox gets populated and when i
select an item then that item appears in the second listbox eg. if i
selected cars from the 1st listbox then cars will appear in the 2nd
listbox instead of BMW, HONDA etc.

I know that my code might be totally wrong as i have no idea what to
do.

My db has 2 tables called CATS with CAT_NAME (Such as cars) and
CAT_ID. The 2nd table is called SUBS and contains SUB_ID, CAT_ID and
SUB_NAME (such as Honda, BMW).It is very important that my code with
read the CAT_ID and SUB_ID as i have to use them later on.
Can someone please help me?

Thanks
Here is my code:

Dim objconn As New ADODB.Connection()
Dim rsx As New ADODB.Recordset()
Dim sLastManufacturer
Dim manufacturer As New ListBox()
objConn = Server.CreateObject("adodb.connection")
objConn.OPEN("Provider=Microsoft.Jet.OLEDB.4.0;Dat a Source=" &
Server.MapPath("/duclassified.mdb"))
rsX = Server.CreateObject("ADODB.Recordset")
rsx.Open("SELECT CAT_NAME, CAT_ID FROM CATS", objConn)

If rsX.EOF Then
Response.Write("No category.<BR>")

Else
' write the CATEGORY listbox...

Response.Write("<SELECT NAME=""manufacturer"" SIZE=15" & _
" ONCHANGE=""manuselected(this);"" >")
' write the entry code for the javascript...
Dim sJavaScript = "function manuselected(elem){" &
Environment.NewLine & _
"for (var i = model." & _
"options.length; i >= 0; i--){" & Environment.NewLine & _
"model.options[i] = null;" & _
Environment.NewLine
' loop through the recordset...
Do Until rsx.EOF
' is this a new manufacturer?
Dim cat_names = rsx("cat_name").Value

If (sLastManufacturer) <> "CAT_Names" Then
' if so, add an entry to the first listbox
sLastManufacturer = rsx("CAT_Name").Value
Response.Write("<OPTION VALUE=" & rsx("CAT_ID").Value & ">"
& sLastManufacturer & "</OPTION>")
' and add a new section to the javascript...
sJavaScript = sJavaScript & "}" &
Environment.NewLine & "if (elem.options[elem.selectedIndex].value==" &
_
rsx("CAT_ID").Value & "){" & Environment.NewLine
& ""
End If
' and add a new model line to the javascript...
sJavaScript = sJavaScript & _
"model.options[" & _
"model.options.length] = new Option('" & _
rsx("CAT_NAME").Value & "','" & rsx("CAT_ID").Value
& _
"');" & _
Environment.NewLine
rsx.MoveNext()
Loop
' finish the manufacturer listbox...
Response.Write("</SELECT>")

rsx.Close()
rsx = Nothing
objconn.Close()
objconn = Nothing

' create the SUBS listbox...

Dim rsSubs As New ADODB.Recordset()
objconn = Server.CreateObject("adodb.connection")
objconn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Dat a Source=" &
Server.MapPath("/duclassified.mdb"))
rsSubs = Server.CreateObject("ADODB.Recordset")
rsSubs.Open("SELECT SUB_NAME, SUB_ID from SUBS where cat_ID =" &
manufacturer.SelectedItem.Value.ToString, objconn)
Response.Write("<SELECT NAME=""model"" SIZE=15>")
Response.Write("<OPTION>[none currently selected]</OPTION>")
Response.Write("</SELECT>")
' put the last line on the javascript...
' and write it out...
sJavaScript = sJavaScript & Environment.NewLine & "}" &
Environment.NewLine & _
"}" & Environment.NewLine
Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" &
Environment.NewLine)
Response.Write(sJavaScript & Environment.NewLine & "</SCRIPT>" &
Environment.NewLine)
End If
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cor
Hi Collie,

As far as I can see it, is what you are doing totaly classic ASP, that is a
little bit far out of the intrest of the visitors of this newsgroup.

I think you have a better change for that in the special newsgroups for ASP.
This newsgroup is for the VB.Net language some things looks like it, but it
is not the same.

(It is also not ASP.Net, so watch what newsgroup you choose).

I hope you get your help.

Cor
Nov 20 '05 #2

P: n/a
Cor
Hi Collie,

As far as I can see it, is what you are doing totaly classic ASP, that is a
little bit far out of the intrest of the visitors of this newsgroup.

I think you have a better change for that in the special newsgroups for ASP.
This newsgroup is for the VB.Net language some things looks like it, but it
is not the same.

(It is also not ASP.Net, so watch what newsgroup you choose).

I hope you get your help.

Cor
Nov 20 '05 #3

P: n/a


Hi,

I don't think that a classic ASP newsgroup will help me as I need to do
this with .net.
I need to create 2 listboxes that are read from the db. the 2nd is
populated based on what the user selected from the 1st box. I currently
did it using postback and it works great. However, my boss now decided
that he doesn't want the page to postback each time a user selects an
item. He wants to use jscript. Also, he does't want to use ado.net and
the db is ACCESS.

How can I do that in .net?
The project is written in vb.net.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4

P: n/a
Cor
Hi Collie,

I did look deeper at your code but I think I cannot help you, because the
code is something not to be the best, but only because your boss wants it in
that way.

(I understand that it is not your wish or fault, so I am not able to help
you I think, because every suggestion will be answered with, "My boss won't
that").

Sorry for you.

Cor



Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.