Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > clear the display box of dropdownList in code

Reply
Thread Tools

clear the display box of dropdownList in code

 
 
Northern
Guest
Posts: n/a
 
      07-19-2003
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
 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-19-2003
Is it that you just want to return to the default setting?

DropDownList1.SelectedIndex = 0

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

DropDownList1.Items.RemoveAt(DropDownList1.Selecte dIndex)

Ken
MVP [ASP.NET]

"Northern" <(E-Mail Removed)> wrote in message
news:002f01c34e23$748ceb00$(E-Mail Removed)...
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


 
Reply With Quote
 
 
 
 
Northern
Guest
Posts: n/a
 
      07-19-2003
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.SelectedIndex = 0
>
>Or remove the one that is selected and leave the rest?
>
>DropDownList1.Items.RemoveAt(DropDownList1.Select edIndex)
>
>Ken
>MVP [ASP.NET]
>
>"Northern" <(E-Mail Removed)> wrote in message
>news:002f01c34e23$748ceb00$(E-Mail Removed)...
>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
>
>
>.
>

 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-19-2003
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.EventArgs) _
Handles Button2.Click
If DropDownList1.Items.IndexOf(DropDownList1.Items.Fi ndByValue("")) = -1
Then
DropDownList1.Items.Insert(0, "")
End If
DropDownList1.SelectedIndex = 0
End Sub

Ken
MVP [ASP.NET]


"Northern" <(E-Mail Removed)> wrote in message
news:03bb01c34e27$4a275a90$(E-Mail Removed)...
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.SelectedIndex = 0
>
>Or remove the one that is selected and leave the rest?
>
>DropDownList1.Items.RemoveAt(DropDownList1.Select edIndex)
>
>Ken
>MVP [ASP.NET]
>
>"Northern" <(E-Mail Removed)> wrote in message
>news:002f01c34e23$748ceb00$(E-Mail Removed)...
>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
>
>
>.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
div box questions; float text around a box, fit box to image size Gnarlodious HTML 4 05-05-2010 11:30 AM
Response.Clear() doesn't clear David ASP .Net 2 01-31-2008 08:32 PM
Unbind a DataSource and clear a DropDownList selection Gaetan ASP .Net 1 05-02-2007 08:51 PM
Unrecognized element 'add' after <clear></clear> InvalidLastName ASP .Net Web Services 3 03-06-2007 03:07 AM
What exactly does dropdownlist.clear do... Ryan ASP .Net 2 11-08-2005 08:50 PM



Advertisments