How do i default back to 'Please Select' in a dropdownlist after a selection has been made?

Last post 01-04-2008 11:35 AM by dbp_n_fl. 4 replies.

Sort Posts:

  • How do i default back to 'Please Select' in a dropdownlist after a selection has been made?

    11-14-2006, 5:02 AM
    • Loading...
    • HerdingCats
    • Joined on 11-08-2006, 9:03 AM
    • Posts 4

    I am using a datasource that queries a database to populate my dropdwon list. After an item has been selected a repeater is populated on the value of this selection. The dropdownlist is set to autopostback. I want the repeater to be populated but the dropdownlist to be set back to "Please select".

     I have set the enableViewState to false but the value is still retained.

     Has anyone any ideas?

     Thanks

  • Re: How do i default back to 'Please Select' in a dropdownlist after a selection has been made?

    11-14-2006, 5:19 AM
    • Loading...
    • Fredrik N
    • Joined on 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,333
    • Moderator
    You can for example call the ClearSelection method of the DropDownList to clear all the selected items, or set the SelectedIndex to the index of the item tha should be selected.
    /Fredrik Normén NSQUARED2
    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog, ASP.Net 2.0 etc

    Cornerstone AB
  • Re: How do i default back to 'Please Select' in a dropdownlist after a selection has been made?

    11-14-2006, 6:37 AM
    • Loading...
    • HerdingCats
    • Joined on 11-08-2006, 9:03 AM
    • Posts 4

    Thanks Fredrik.

     I used the ClearSelection method and it worked a treat.

  • Re: How do i default back to 'Please Select' in a dropdownlist after a selection has been made?

    01-04-2008, 8:31 AM
    • Loading...
    • Garrydias
    • Joined on 12-21-2007, 12:18 PM
    • Rio de Janeiro, RJ
    • Posts 26

    Hello

    I´m using a datasource to populate my dropdownlist.

    My query results has this face:

    id          |             data

    1                         data1
    2                         data2
    3                         data3
    4                         data4

    And my dropdownlist has this face:

    data1
    data2
    data3
    data4

    My problem is: I want my dropdownlist with this face:

    Select Your Data
    data1
    data2
    data3
    data4

    The 'Select Your Data' text cannot be a query result. I made it in code behind using collections lists. Does have another way to do it?

    Garry Dias, Rio de Janeiro, Brazil
    "I don´t wait nothing fall from the sky. I knock down rigth away!!"
  • Re: How do i default back to 'Please Select' in a dropdownlist after a selection has been made?

    01-04-2008, 11:35 AM
    • Loading...
    • dbp_n_fl
    • Joined on 12-24-2007, 10:20 AM
    • Central Florida
    • Posts 41

    You could try this:

    Make sure the AppendDataBoundItems = "true" is set, that way the data bound items will appear after the Select your data item

    <asp:DropDownList ID="DDList" AppendDataBoundItems="True" runat="server" Width="152px" DataSourceID="SqlDataSource1" DataTextField="Data Text" DataValueField="Data Value">

    <asp:ListItem Text="Select Your Data" />

    </asp:DropDownList>

     

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter