Multiple DropDownLists

I

Igor

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/archive/2006/01/29/436804.aspx). To enable
that I had to set the AppendDataBoundItems 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
AppendDataBoundItems 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
 
I

Igor

Hi

I didn't make myself clear enough. Where should I put it in the code ? I
tried putting it in SelectedIndexChanged 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
 
D

David Wier

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
 
I

Igor

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="">.
 
M

Mark Elliott

Would something like the following work?

DropDownList ddl = new DropDownList();
ListItem li = new ListItem("--select item--");
ddl.Items.Insert(li);
 
M

mahesh reddy

i m also facing same prblm
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/archive/2006/01/29/436804.aspx). To enable
that I had to set the AppendDataBoundItems 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
AppendDataBoundItems 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top