473,804 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple DropDownLists

Hello

I have the following problem. I have three drop down lists on my page. They
are filled with data from a database. Initially only the first one is
enabled. The next one is enebled when user selects an item from the first
one -- it is then filled with data specific to the selection in the drop
down list above. The same with the third one. For each drop down list the
first item is always "--select an item--" (as described here:
http://weblogs.asp.net/scottgu/archi...9/436804.aspx). To enable
that I had to set the AppendDataBound Items property for all three drop down
lists to "true". Unfortunatelly, when a user selects an item from the first
drop down list, the second one gets filled with item "--select an item--"
and data from the database. But if the user changes their mind and selects
different item from the first list (or list above in the structure) the next
drop down list gets filled with new data, but, because of the
AppendDataBound Items property set to "true", previous data remains in the
list. Thus, I must clear list(s) when user makes change to the selection
above in the structure. How can I do this?

Kind regards

IgorM

Jun 27 '08 #1
6 1981
ddl.items.clear

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Igor" <ig***@live.com wrote in message
news:22******** *************** ***********@mic rosoft.com...
Hello

I have the following problem. I have three drop down lists on my page.
They are filled with data from a database. Initially only the first one is
enabled. The next one is enebled when user selects an item from the first
one -- it is then filled with data specific to the selection in the drop
down list above. The same with the third one. For each drop down list the
first item is always "--select an item--" (as described here:
http://weblogs.asp.net/scottgu/archi...9/436804.aspx). To enable
that I had to set the AppendDataBound Items property for all three drop
down lists to "true". Unfortunatelly, when a user selects an item from the
first drop down list, the second one gets filled with item "--select an
item--" and data from the database. But if the user changes their mind and
selects different item from the first list (or list above in the
structure) the next drop down list gets filled with new data, but, because
of the AppendDataBound Items property set to "true", previous data remains
in the list. Thus, I must clear list(s) when user makes change to the
selection above in the structure. How can I do this?

Kind regards

IgorM

Jun 27 '08 #2
Hi

I didn't make myself clear enough. Where should I put it in the code ? I
tried putting it in SelectedIndexCh anged events of particular drop down
lists as well as PageLoad event but than I had a problem with a statement
that selects first item (the one with "--select item --" text ) in the drop
down lists below in the hierarchy because it fired exceptions. By
ddl.items.clear the first item, the "--select item--" is also cleares, and
it is not added again in postbacks.

Kind regars
IgorM

"David Wier" <dw@dw.comwro te in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
ddl.items.clear

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
no bloated markup
"Igor" <ig***@live.com wrote in message
news:22******** *************** ***********@mic rosoft.com...
>Hello

I have the following problem. I have three drop down lists on my page.
They are filled with data from a database. Initially only the first one
is enabled. The next one is enebled when user selects an item from the
first one -- it is then filled with data specific to the selection in the
drop down list above. The same with the third one. For each drop down
list the first item is always "--select an item--" (as described here:
http://weblogs.asp.net/scottgu/archi...9/436804.aspx). To enable
that I had to set the AppendDataBound Items property for all three drop
down lists to "true". Unfortunatelly, when a user selects an item from
the first drop down list, the second one gets filled with item "--select
an item--" and data from the database. But if the user changes their mind
and selects different item from the first list (or list above in the
structure) the next drop down list gets filled with new data, but,
because of the AppendDataBound Items property set to "true", previous data
remains in the list. Thus, I must clear list(s) when user makes change to
the selection above in the structure. How can I do this?

Kind regards

IgorM

Jun 27 '08 #3
You should put it anywhere you need it, in any event handler, just before
you're populating the ddl.
Anothere thing - if you're populating any ddls in the Page_Load event, be
sure to surround that population with an if/then/Postback block

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Igor" <ig***@live.com wrote in message
news:0D******** *************** ***********@mic rosoft.com...
Hi

I didn't make myself clear enough. Where should I put it in the code ? I
tried putting it in SelectedIndexCh anged events of particular drop down
lists as well as PageLoad event but than I had a problem with a statement
that selects first item (the one with "--select item --" text ) in the
drop down lists below in the hierarchy because it fired exceptions. By
ddl.items.clear the first item, the "--select item--" is also cleares, and
it is not added again in postbacks.

Kind regars
IgorM

"David Wier" <dw@dw.comwro te in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>ddl.items.clea r

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
no bloated markup
"Igor" <ig***@live.com wrote in message
news:22******* *************** ************@mi crosoft.com...
>>Hello

I have the following problem. I have three drop down lists on my page.
They are filled with data from a database. Initially only the first one
is enabled. The next one is enebled when user selects an item from the
first one -- it is then filled with data specific to the selection in
the drop down list above. The same with the third one. For each drop
down list the first item is always "--select an item--" (as described
here: http://weblogs.asp.net/scottgu/archi...9/436804.aspx). To
enable that I had to set the AppendDataBound Items property for all three
drop down lists to "true". Unfortunatelly, when a user selects an item
from the first drop down list, the second one gets filled with item
"--select an item--" and data from the database. But if the user changes
their mind and selects different item from the first list (or list above
in the structure) the next drop down list gets filled with new data,
but, because of the AppendDataBound Items property set to "true",
previous data remains in the list. Thus, I must clear list(s) when user
makes change to the selection above in the structure. How can I do this?

Kind regards

IgorM


Jun 27 '08 #4
Still don't know how to get the first item to be "--select value--" in code
behind if I cannot use the <asp:ListItem Text="-- select value --"
Value="">.
"David Wier" <dw@dw.comwro te in message
news:O8******** ******@TK2MSFTN GP02.phx.gbl...
You should put it anywhere you need it, in any event handler, just before
you're populating the ddl.
Anothere thing - if you're populating any ddls in the Page_Load event, be
sure to surround that population with an if/then/Postback block

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
no bloated markup
"Igor" <ig***@live.com wrote in message
news:0D******** *************** ***********@mic rosoft.com...
>Hi

I didn't make myself clear enough. Where should I put it in the code ? I
tried putting it in SelectedIndexCh anged events of particular drop down
lists as well as PageLoad event but than I had a problem with a statement
that selects first item (the one with "--select item --" text ) in the
drop down lists below in the hierarchy because it fired exceptions. By
ddl.items.clea r the first item, the "--select item--" is also cleares,
and it is not added again in postbacks.

Kind regars
IgorM

"David Wier" <dw@dw.comwro te in message
news:%2******* *********@TK2MS FTNGP04.phx.gbl ...
>>ddl.items.cle ar

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
with no bloated markup
"Igor" <ig***@live.com wrote in message
news:22****** *************** *************@m icrosoft.com...
Hello

I have the following problem. I have three drop down lists on my page.
They are filled with data from a database. Initially only the first one
is enabled. The next one is enebled when user selects an item from the
first one -- it is then filled with data specific to the selection in
the drop down list above. The same with the third one. For each drop
down list the first item is always "--select an item--" (as described
here: http://weblogs.asp.net/scottgu/archi...9/436804.aspx).
To enable that I had to set the AppendDataBound Items property for all
three drop down lists to "true". Unfortunatelly, when a user selects an
item from the first drop down list, the second one gets filled with
item "--select an item--" and data from the database. But if the user
changes their mind and selects different item from the first list (or
list above in the structure) the next drop down list gets filled with
new data, but, because of the AppendDataBound Items property set to
"true", previous data remains in the list. Thus, I must clear list(s)
when user makes change to the selection above in the structure. How can
I do this?

Kind regards

IgorM


Jun 27 '08 #5
Would something like the following work?

DropDownList ddl = new DropDownList();
ListItem li = new ListItem("--select item--");
ddl.Items.Inser t(li);

On Thu, 12 Jun 2008 13:57:18 -0300, Igor <ig***@live.com wrote:
Still don't know how to get the first item to be "--select value--" in
code behind if I cannot use the <asp:ListItem Text="-- select value --"
Value="">.
"David Wier" <dw@dw.comwro te in message
news:O8******** ******@TK2MSFTN GP02.phx.gbl...
>You should put it anywhere you need it, in any event handler, just
before you're populating the ddl.
Anothere thing - if you're populating any ddls in the Page_Load event,
be sure to surround that population with an if/then/Postback block

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
with no bloated markup
"Igor" <ig***@live.com wrote in message
news:0D******* *************** ************@mi crosoft.com...
>>Hi

I didn't make myself clear enough. Where should I put it in the code ?
I tried putting it in SelectedIndexCh anged events of particular drop
down lists as well as PageLoad event but than I had a problem with a
statement that selects first item (the one with "--select item --"
text ) in the drop down lists below in the hierarchy because it fired
exceptions. By ddl.items.clear the first item, the "--select item--"
is also cleares, and it is not added again in postbacks.

Kind regars
IgorM

"David Wier" <dw@dw.comwro te in message
news:%2****** **********@TK2M SFTNGP04.phx.gb l...
ddl.items.cl ear

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
with no bloated markup
"Igor" <ig***@live.com wrote in message
news:22***** *************** **************@ microsoft.com.. .
Hello
>
I have the following problem. I have three drop down lists on my
page. They are filled with data from a database. Initially only the
first one is enabled. The next one is enebled when user selects an
item from the first one -- it is then filled with data specific to
the selection in the drop down list above. The same with the third
one. For each drop down list the first item is always "--select an
item--" (as described here:
http://weblogs.asp.net/scottgu/archi...9/436804.aspx). To
enable that I had to set the AppendDataBound Items property for all
three drop down lists to "true". Unfortunatelly, when a user selects
an item from the first drop down list, the second one gets filled
with item "--select an item--" and data from the database. But if
the user changes their mind and selects different item from the
first list (or list above in the structure) the next drop down list
gets filled with new data, but, because of the AppendDataBound Items
property set to "true", previous data remains in the list. Thus, I
must clear list(s) when user makes change to the selection above in
the structure. How can I do this?
>
Kind regards
>
IgorM



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jun 27 '08 #6
Perhaps you can use this free control to make your life easier:
http://www.asp.net/AJAX/AjaxControlT...gDropDown.aspx

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
http://iPhonePlaza.net
"Igor" <ig***@live.com wrote in message
news:22******** *************** ***********@mic rosoft.com...
Hello

I have the following problem. I have three drop down lists on my page.
They are filled with data from a database. Initially only the first one is
enabled. The next one is enebled when user selects an item from the first
one -- it is then filled with data specific to the selection in the drop
down list above. The same with the third one. For each drop down list the
first item is always "--select an item--" (as described here:
http://weblogs.asp.net/scottgu/archi...9/436804.aspx). To enable
that I had to set the AppendDataBound Items property for all three drop
down lists to "true". Unfortunatelly, when a user selects an item from the
first drop down list, the second one gets filled with item "--select an
item--" and data from the database. But if the user changes their mind and
selects different item from the first list (or list above in the
structure) the next drop down list gets filled with new data, but, because
of the AppendDataBound Items property set to "true", previous data remains
in the list. Thus, I must clear list(s) when user makes change to the
selection above in the structure. How can I do this?

Kind regards

IgorM
Jun 27 '08 #7

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

Similar topics

0
2129
by: theo | last post by:
Hello..I have a similar issue as yesterday but the situation has slightly changed so perhaps someone can shed some more light on the issue... Program flow - load file,extract xml text tags from file,then depending on the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the placeholder,the user selects the required tags from the dropdownlists (if 5 Xml tags,then 5 dropdownlists...
4
3626
by: Craig Buchanan | last post by:
I would like to reuse a SQLDataReader that is populated with information as the datasource for multiple dropdownlists. Unfortunately, the first DDL closes the SDR and my code fails on the second DDR. Is there a way to copy/clone the SDR? Is there another solution? Thanks, Craig Buchanan
2
1333
by: Harry | last post by:
Hi, Quick question regarding dropdownlists. On one page I have 10 asp:dropdownlists. The user selects an option from a dropdown list and then it updates an asp:label with the relevant text. The user must select an option from each dropdown list. All the dropdownlists are to be populated from a SQL database.
1
1006
by: Angel.Net | last post by:
I'm working with 40 dropdownlists that are selected on the the first page and each selection is sent to another Web Page's textboxes. I'd like to loop thru my first page's dropdown's and match them with the second page's textboxes. Should the controls on both pages be established in an ArrayList?? What is the best way to access these controls without hardcoding their id's? From...
9
5340
by: Timm | last post by:
I have an ASP.NET 2.0 page with two DropDownLists. I am using declarative data binding wherever possible and trying to minimize the use of code. The list of values in DropDownList DDL2 should be (filtered) dependent upon the selection in DDL1. I think this inevitably needs some code, but I'd be happy to be told otherwise! I have some code to handle OnSelectedIndexChanged for DDL1 that sets the FilterExpression associated with the...
10
6395
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but still error occurs. I need information on this. Thanks. Ads
11
3156
by: Ranginald | last post by:
This question is about how to handle an .aspx page that references multiple methods and where to store these methods (e.g. one codefile or multiple codefiles). PREFACE ======== I have a simple category/product asp.net/C# web site I am coding in web dev express and laying out in dreamweaver MX. I find the layout tools in web express difficult to use and implementation of complex templates much easier in dwmx.
3
1653
by: RSH | last post by:
Hi, I am having this very bizarre occurance with 4 dropdown lists on my ASP .Net page. Each control has its own unique id. When the user selects a value from each of the dropdownlists it is written correctly to the database. HOWEVER...When setting the SelectedIndex property of each of the controls in the codebehind (.net 1.1) I get an exception "A dropdownlist can not have
4
6137
by: =?Utf-8?B?TWFkaXNvbg==?= | last post by:
Hi all, Could I use the sqldatasource with stored-procedure to return multiple recordset? I did not want to have any sqldatasourec in the one page just to return the record back to dropdownlists. In my stored procedure will have 2 select statement. If it can be done how I refer to each dropdownlist to correct recordset. Please advise. Thanks.
1
1309
by: klaul | last post by:
I've been trying to do this for a day and a half now, and am clearly getting nowhere! The database I'm using is used to keep a log of service calls to various companies. When the user inserts data, they choose the company from a static list, but the reference number is user-supplied. The data is brought back using a GridView. I am trying to create two linked dropdownlists so that I can search the gridview (so that the items on the second...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
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
10311
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
10074
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
9138
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
7613
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
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4292
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
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.