473,326 Members | 2,099 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,326 software developers and data experts.

Dynamic drop down list

Hi:
I have to basically populate another dropdown list based on the first
dropdown list.My first dropdown list contains only two values i.e
1.City
2.County
So the second dropdownlist should contain the values of either one of
those based on the selection.I have used the followind code in the
"Indexchanged" event of the first dropdown list.

Private Sub ddlprogtype_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlprogtype.SelectedIndexChanged
Connection.Open()
Dim X As String = ddlprogtype.SelectedValue
lbldisplay.Text = ddlprogtype.SelectedValue
Command.CommandText = "Select names from tblregions where type
= " + "@x"
DataReader = Command.ExecuteReader
ddlnames.DataSource = DataReader
ddlnames.DataBind()
Connection.Close()

End Sub
Upon compiling I am getting the following error message

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object with error being pointed to the
following line
\Line 79: Command.CommandText = "Select places from tblRegions
where type = " + "@x"

Kindly advise on how I should tackle this error.Thanks
Jagdish.l

Nov 19 '05 #1
3 1349
try setting Command to a valid object. then it'll blow up because you
haven't added the parameter referenced in the commandtext.

-- bruce (sqlwork.com)
<ja******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi:
I have to basically populate another dropdown list based on the first
dropdown list.My first dropdown list contains only two values i.e
1.City
2.County
So the second dropdownlist should contain the values of either one of
those based on the selection.I have used the followind code in the
"Indexchanged" event of the first dropdown list.

Private Sub ddlprogtype_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlprogtype.SelectedIndexChanged
Connection.Open()
Dim X As String = ddlprogtype.SelectedValue
lbldisplay.Text = ddlprogtype.SelectedValue
Command.CommandText = "Select names from tblregions where type
= " + "@x"
DataReader = Command.ExecuteReader
ddlnames.DataSource = DataReader
ddlnames.DataBind()
Connection.Close()

End Sub
Upon compiling I am getting the following error message

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object with error being pointed to the
following line
\Line 79: Command.CommandText = "Select places from tblRegions
where type = " + "@x"

Kindly advise on how I should tackle this error.Thanks
Jagdish.l

Nov 19 '05 #2
"ja******@gmail.com" wrote:
Hi:
I have to basically populate another dropdown list based on the first
dropdown list.My first dropdown list contains only two values i.e
1.City
2.County
So the second dropdownlist should contain the values of either one of
those based on the selection.I have used the followind code in the
"Indexchanged" event of the first dropdown list.

Private Sub ddlprogtype_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlprogtype.SelectedIndexChanged
Connection.Open()
Dim X As String = ddlprogtype.SelectedValue
lbldisplay.Text = ddlprogtype.SelectedValue
Command.CommandText = "Select names from tblregions where type
= " + "@x"
DataReader = Command.ExecuteReader
ddlnames.DataSource = DataReader
ddlnames.DataBind()
Connection.Close()

End Sub
Upon compiling I am getting the following error message

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object with error being pointed to the
following line
\Line 79: Command.CommandText = "Select places from tblRegions
where type = " + "@x"

Kindly advise on how I should tackle this error.Thanks
Jagdish.l


Hi:

I decided to make the program much more simple by making the following
modifications

Private Sub ddlprogtype_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlprogtype.SelectedIndexChanged
Connection.Open()
lbldisplay.Text = ddlprogtype.SelectedValue
Dim X As String = ddlprogtype.SelectedValue
If X = "County" Then
Command.CommandText = "Select Countyname from tblcounties"
ElseIf X = "City" Then
Command.CommandText = "Select Cityname from tblcities"
End If
DataReader = Command.ExecuteReader
ddlnames.DataSource = DataReader
ddlnames.DataBind()
Connection.Close()
This took care of the error message but the dropdownlist is not being
populated by the values..What is wrong?
Thanks

Jagdish.l

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 19 '05 #3
Hi:
Thanks for the above tip.To make it more simple I replaced it with
the following code

Private Sub ddlprogtype_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlprogtype.SelectedIndexChanged
Connection.Open()
lbldisplay.Text = ddlprogtype.SelectedValue
Dim X As String = ddlprogtype.SelectedValue
If X = "County" Then
Command.CommandText = "Select Countyname from tblcounties"
ElseIf X = "City" Then
Command.CommandText = "Select Cityname from tblcities"
End If
DataReader = Command.ExecuteReader
ddlnames.DataSource = DataReader
ddlnames.DataBind()
Connection.Close()

This took care of the error message but the dropdown list is not
getting populated by the values.It is still blank..Do I need to add any
further piece of code to the seconddrop down list...such as databinding
etc...I would really appreciate your advice..
Thanks once again.

Jagdish.l

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kingdom | last post by:
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car' and the second box will list all the car...
5
by: C White | last post by:
I'm trying to write an asp script that will create a series of drop lists based on a table like: canada ontario toronto street name link canada ontario toronto road...
1
by: ayende | last post by:
Okay, I'm pretty sure that I'm doing everything right here, but something is very wrong in the result. I've a page that has a drop down list (with auto-post-back = true) and a place holder. ...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
1
by: Jeff Gardner | last post by:
Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
4
by: phcmi | last post by:
I have a PropertyGrid question. My task is to replace a legacy dialog box presentation with a modern one. The dialog itself allows the user to set configuration settings in our application, so...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
4
by: audreyality | last post by:
I am new to javascript and appreciate any guidance on this issue, so thank you in advance for your advice! Situation: I am working with a form that will send information to a database. I need the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.