What exactly does dropdownlist.clear do...

R

Ryan

I have a dropdown list bound to a datasource. I would like to clear it
at the press of a button. I tried using the following code:

mydropdown.Items.Clear()

The end result is that it comes back unchanged.

I then thought to myself maybe it has to do with the viewstate so I I
kept adding more and more code until I ended up with the following:

ViewState.Clear()
ClearChildViewState()
mydropdown.AutoPostBack = False
mydropdown.EnableViewState = False
mydropdown.Items.Clear()

Again, I just got my orignal list back. So does items.clear() not have
an effect on the control once it has been databound the very first
time.

Additionally, is it better to loop through all my controls and blank
them out, which would, if there is no fast method of clearing a drop
down list, mean looping through and removing each item from the drop
down list, OR to response.redirect back to my page. When I say better
I mean faster to the end-user...

Thanks,
Ryan
 
G

Guest

You aren't repopulating it in the Page_Load are you?
Make sure you are checking for IsPostBack
 
S

S. Justin Gengo

Ryan,

How are you binding your list's items? Are the items being re-bound after
you clear it?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top