473,654 Members | 3,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clear the display box of dropdownList in code

I need to write code clear the display box of my
DropDownList (something like clear current selected item)
while still keep the loaded item list in the DropDownList.

I tried DropDownList's ClearSelecttion () method and set
SelectedIndex to -1 but neither works.

How should I do this?

Thanks
Nov 17 '05 #1
3 7806
Is it that you just want to return to the default setting?

DropDownList1.S electedIndex = 0

Or remove the one that is selected and leave the rest?

DropDownList1.I tems.RemoveAt(D ropDownList1.Se lectedIndex)

Ken
MVP [ASP.NET]

"Northern" <li******@msn.c om> wrote in message
news:00******** *************** *****@phx.gbl.. .
I need to write code clear the display box of my
DropDownList (something like clear current selected item)
while still keep the loaded item list in the DropDownList.

I tried DropDownList's ClearSelecttion () method and set
SelectedIndex to -1 but neither works.

How should I do this?

Thanks
Nov 17 '05 #2
I guess I didn't phrase my question clearly.
I don't want to remove anything from the list's item
collection. What I want is just to clear the current
selection so that the display box of the dropdownbox on
the form will be blank. But if now I click on the dropdown
again, I can see all items are still there.

Thanks
-----Original Message-----
Is it that you just want to return to the default setting?

DropDownList1.S electedIndex = 0

Or remove the one that is selected and leave the rest?

DropDownList1. Items.RemoveAt( DropDownList1.S electedIndex)

Ken
MVP [ASP.NET]

"Northern" <li******@msn.c om> wrote in message
news:00******* *************** ******@phx.gbl. ..
I need to write code clear the display box of my
DropDownList (something like clear current selected item)
while still keep the loaded item list in the DropDownList.

I tried DropDownList's ClearSelecttion () method and set
SelectedInde x to -1 but neither works.

How should I do this?

Thanks
.

Nov 17 '05 #3
I think the dropdownlist defaults to the first item in the order.

If you want nothing to appear, you would have to have a "blank" item as the
first item in the list. You could either add this when you build the
dropdownlist or later when you wanted to reset the appearance:

Private Sub Button2_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles Button2.Click
If DropDownList1.I tems.IndexOf(Dr opDownList1.Ite ms.FindByValue( "")) = -1
Then
DropDownList1.I tems.Insert(0, "")
End If
DropDownList1.S electedIndex = 0
End Sub

Ken
MVP [ASP.NET]
"Northern" <li******@msn.c om> wrote in message
news:03******** *************** *****@phx.gbl.. .
I guess I didn't phrase my question clearly.
I don't want to remove anything from the list's item
collection. What I want is just to clear the current
selection so that the display box of the dropdownbox on
the form will be blank. But if now I click on the dropdown
again, I can see all items are still there.

Thanks
-----Original Message-----
Is it that you just want to return to the default setting?

DropDownList1.S electedIndex = 0

Or remove the one that is selected and leave the rest?

DropDownList1. Items.RemoveAt( DropDownList1.S electedIndex)

Ken
MVP [ASP.NET]

"Northern" <li******@msn.c om> wrote in message
news:00******* *************** ******@phx.gbl. ..
I need to write code clear the display box of my
DropDownList (something like clear current selected item)
while still keep the loaded item list in the DropDownList.

I tried DropDownList's ClearSelecttion () method and set
SelectedInde x to -1 but neither works.

How should I do this?

Thanks
.

Nov 17 '05 #4

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

Similar topics

2
3111
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit is performed. How do I force the usercontrol to display the newly assigned date? I don't have this problem if I place the two dropdownlist and the year field directly on the aspx page.
1
4078
by: Anonieko Ramos | last post by:
> > > How to display multiple spaces in a dropdownlist webform1.aspx <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
1
1455
by: Xuanly ly via .NET 247 | last post by:
asp:dropdownlist always display infront of everything and I can't make it display behind HELP HELP help!!!. <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1" runat="server" style="Z-INDEX: 1; LEFT: 50px; POSITION: absolute; TOP: 300px" Width="250px"></asp:TextBox> <asp:panel id="pnCal runat="server" Width="156px" Height="128px" style=" LEFT: 50px; POSITION: absolute; TOP: 300px"> <asp:Calendar id="Calendar1"...
1
2394
by: Chris | last post by:
Hi, I have a page with quite a few textboxes and dropdownlist controls. How can I clear the textboxes and reset the dropdownlist after the data is sent to the database? Do I have to perform textbox1.text = "" textbox2.text = "" .....
1
1871
by: Trevor Bezotte | last post by:
Hi, I'm new to asp.net. I am having trouble updating and displaying a profile property through a dropdownlist. I believe the problem has something to do with autoeventwireup but I'm not sure. If I change the selection in the dropdownlist and click Button1, the profiles database gets updated and the control shows my new selection, but when I browse to a different page and come back to this page, the dropdownlist gets set back to the default...
3
1475
by: Jeff User | last post by:
Greeting I built asp.net (V1.1) page. I want to use this button to reset SelectedIndex=0 on several drop down lists. However, I do not want to post back to server. The point is to avoid the round trip. It had an asp:button which would post back to the server when clicked but changed it to an input button to avoid the postback. (If that is not needed,let me know)
2
2061
by: mervyntracy | last post by:
Hi There, I have recently started coding in asp.net (just 2 and a half days now). I am writing a simple test app that gets data from a data base and displays the value perfectly in the drop down list. However, each display value is simply that - a display value and is pretty useless to me further down the line unless I use the value as part of a select to get the the key of the record. This would be inefficent so what I would like to...
1
1683
by: Wingot | last post by:
Hey, I have an application codenamed WingFlex. It has a number of aspects to it, but the prudent parts for this problem are all within the "Client" Schema. The Client schema has three tables in it, on named Country, one named MedicalCondition, and one named Customer. The Customer database has five foreign keys in it, one to Country, one to MedicalCondition, and three as self referential keys to Customer (BillTo, for where the
0
1049
by: AlDave | last post by:
What I'm trying display is after the user chooses the product (1st category) from a dropdown, then the dataview will display; The category any reports under that subcategory any reports under that
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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
8814
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
8706
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...
0
8591
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...
1
6160
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
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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
1
1915
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.