473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Listbox w/o Autopostback

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
4 1842
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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vengeance | last post by:
On the parent_form.aspx I have these controls <asp:listbox id="Operators" runat="server" Width="163px" SelectionMode="Multiple" Rows="2"></asp:listbox> <INPUT class="loButton" onclick="java...
2
by: Allan Horwitz | last post by:
When I try to reference the lstproducts.selecteditem.value using autopostback from the lstproducts listbox I get an error? How can I fix my code to get the selected value from the lstproducts...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
2
by: ben | last post by:
Hi All, I have a Listbox which gets populated from the database.On selecting an item in the list, i would like to populate some other fields......it was working fine until i added...
2
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the...
1
by: Daniel | last post by:
hi, I had an asp:listbox, and everytime i click item inside, the bar automatically go to the top, is there any way to keep the scroll position? I turn on the smartNavigation, it still doesn't...
6
by: Steve | last post by:
Hi, I open up a webform (vb.net) and populate a listbox control on the Page load event. If I click on (select) and item from the listbox I want to write the value of the selected item to a...
3
by: Raja | last post by:
I have a simple question, I have a datagrid and inside the grid, i have List box. I am able to render the page with the datagrid and the lisbox values. Now, my question is how to trap the server...
6
by: msnews.microsoft.com | last post by:
Hi All, I am creating a control with ASP "ListBox" control. Also I have added necessary code to handle the ListBox.SelectedItemChanged Event. But surprisingly the control is not comng to...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.