473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Connectio n()
Dim rsx As New ADODB.Recordset ()
Dim sLastManufactur er
Dim manufacturer As New ListBox()
objConn = Server.CreateOb ject("adodb.con nection")
objConn.OPEN("P rovider=Microso ft.Jet.OLEDB.4. 0;Data Source=" &
Server.MapPath( "/duclassified.md b"))
rsX = Server.CreateOb ject("ADODB.Rec ordset")
rsx.Open("SELEC T 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=""manufact urer"" SIZE=15" & _
" ONCHANGE=""manu selected(this); "" >")
' write the entry code for the javascript...
Dim sJavaScript = "function manuselected(el em){" &
Environment.New Line & _
"for (var i = model." & _
"options.length ; i >= 0; i--){" & Environment.New Line & _
"model.opti ons[i] = null;" & _
Environment.New Line
' loop through the recordset...
Do Until rsx.EOF
' is this a new manufacturer?
Dim cat_names = rsx("cat_name") .Value

If (sLastManufactu rer) <> "CAT_Names" Then
' if so, add an entry to the first listbox
sLastManufactur er = rsx("CAT_Name") .Value
Response.Write( "<OPTION VALUE=" & rsx("CAT_ID").V alue & ">"
& sLastManufactur er & "</OPTION>")
' and add a new section to the javascript...
sJavaScript = sJavaScript & "}" &
Environment.New Line & "if (elem.options[elem.selectedIn dex].value==" &
_
rsx("CAT_ID").V alue & "){" & Environment.New Line
& ""
End If
' and add a new model line to the javascript...
sJavaScript = sJavaScript & _
"model.opti ons[" & _
"model.options. length] = new Option('" & _
rsx("CAT_NAME") .Value & "','" & rsx("CAT_ID").V alue
& _
"');" & _
Environment.New Line
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.CreateOb ject("adodb.con nection")
objconn.Open("P rovider=Microso ft.Jet.OLEDB.4. 0;Data Source=" &
Server.MapPath( "/duclassified.md b"))
rsSubs = Server.CreateOb ject("ADODB.Rec ordset")
rsSubs.Open("SE LECT SUB_NAME, SUB_ID from SUBS where cat_ID =" &
manufacturer.Se lectedItem.Valu e.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.New Line & "}" &
Environment.New Line & _
"}" & Environment.New Line
Response.Write( "<SCRIPT LANGUAGE=""Java Script"">" &
Environment.New Line)
Response.Write( sJavaScript & Environment.New Line & "</SCRIPT>" &
Environment.New Line)
End If
End Sub
Nov 20 '05 #1
4 1857
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
2918
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 script:getOptionPicker('?mid=TS5 &callingcontrol=Operators');" type="button" value="+"> <asp:button id="save" runat="server" CssClass="loButton" Text="Save"> </asp:button> I also use a global.js file which adds the following functions
2
1356
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 listbox? Any help will be appreciated. Sincerely, Allan
1
8421
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 I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
2
1773
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 autopostback="true"...now it gives me an error saying"Object does not support this method or property( IE Script error) If i remove the AutoPostBack="true", then the error does not appear.... Code SNippets Follow:
2
2734
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 second one. I seem unable to do this as it only sends back the first item I select whether I have the CTL key down or not. Upon the return trip, I can select another one, but it still only sends value for the last one I selected. -- MY LISTBOX --...
1
9868
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 work. Thanks ahead.
6
6183
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 label control. Nothing happens. But when I click a button (which contains same code to write to label) I get the value of the selected item in the Label.
3
1906
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 side SelectedIndexChanged event of the listbox. Any help in VB.NET would be greatly appreciated. Thanks
6
1453
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 this code at all. Why my ListBox Control in my Web Control is not Raising the
9
3246
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). This listbox has AutoPostback = True. When the user selects an item from this list, the second listbox is populated with more items relevant to this selection. I am using an SQLDataSource web control for this. These items are headers. I want, when...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.