clear the display box of dropdownList in code

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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
    Northern Guest

  2. Similar Questions and Discussions

    1. Unable to display the data in dropdownlist in datagrid
      Hi all, I am unable to display the data in dropdown list in datagrid control. can anybody help me please? my ItemDataBound code is here..... ...
    2. Where Do I Place Date Code for Webpage Display
      Hi, i have had no problem displaying the current date and time, on a static webpage. However, when i try to use the various PHP and MySQL snippets,...
    3. Clear screen
      Hi, I'm using PHP on my Linux box on the command line. It need to clear the screen, as I would do with the 'clear' command on the bash. Is...
    4. how to display variables within using echo command within html code
      this is part of my code question? why the variable $name and $address does not display on the html page instead of real values I do get...
    5. [PHP] Display HTML/PHP code on a web page
      --- Jason Paschal <j_paschal@hotmail.com> wrote: Try htmlentities() Chris ===== Become a better Web developer with the HTTP Developer's...
  3. #2

    Default Re: clear the display box of dropdownList in code

    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" <lifeng26@msn.com> wrote in message
    news:002f01c34e23$748ceb00$a601280a@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


    Ken Cox [Microsoft MVP] Guest

  4. #3

    Default Re: clear the display box of dropdownList in code

    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" <lifeng26@msn.com> wrote in message
    >news:002f01c34e23$748ceb00$a601280a@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
    >
    >
    >.
    >
    Northern Guest

  5. #4

    Default Re: clear the display box of dropdownList in code

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

    Ken Cox [Microsoft MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139