ASP.Net dropdownlist control.   Item Selection and Autopostback

Posted on 2009-02-22
Last Modified: 2012-05-06
Hi all-
I have a 2 part question.  
I have written an application that uses multiple dropdownlist controls.  I use a SQLDataSource to populate each of these controls.
My first question is:
Is there a way to have my dropdownlist controls not display a selected item when the page first loads?  I tried dropdownlist.selectedindex = -1 in the Page_Load event, but that did not work.  Is there another control that I could use that would accomplish this?

My second question is:
I want some controls in my page to be enabled or disabled based on what is selected in one of my dropdownlist controls.  The only way I was able to accomplish this was by setting the AutoPostback to true in my control.  This did the trick in disabling and enabling controls, but it also causes my entire page to refresh and clearing some field values that had already been filled in.  How can I disable some controls and keep my entire page from refreshing?

Thanks in advance,
mainrotor :-)
Question by:mainrotor
    LVL 10

    Expert Comment

    1. dropdownlist.selecteditem = Nothing ?

    2. You can use JavaScript to do this at the client side, unset the AutoPostBack and this will not cause a refresh. Look here for some hints on how to to this on the client side:
    LVL 9

    Accepted Solution

    When page loads thats the place you can do something like below. if you are using any datagrid then you need to call itembound or itemcreate event.

    by default you will have one of the item selected in the DDL.
    lbl_search.Text = RadioBtn_Search.SelectedItem.Text
            If RadioBtn_Search.SelectedItem.Text = "Event Name" Then
                DDL_search.SelectedItem.Text = "Equals"
                DDL_search.Enabled = False
                txt_search.Visible = False
                DDL_SearchEvent.Visible = True
                DDL_search.Enabled = True
                txt_search.Visible = True
                DDL_SearchEvent.Visible = False
            End If
            lbl_Modify.Text = RadioBtn_Modify.SelectedItem.Text
            If RadioBtn_Modify.SelectedItem.Text = "Event Name" Then
                DDL_Modify.SelectedItem.Text = "Equals"
                DDL_Modify.Enabled = False
                txt_Modify.Visible = False
                DDL_ModifyEvent.Visible = True
                DDL_Modify.Enabled = True
                txt_Modify.Visible = True
                DDL_ModifyEvent.Visible = False
            End If
            lbl_delete.Text = RadioBtn_Delete.SelectedItem.Text
            If RadioBtn_Delete.SelectedItem.Text = "Event Name" Then
                ddl_delete.SelectedItem.Text = "Equals"
                ddl_delete.Enabled = False
                txt_Delete.Visible = False
                DDL_DeleteEvent.Visible = True
                ddl_delete.Enabled = True
                txt_Delete.Visible = True
                DDL_DeleteEvent.Visible = False
            End If

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and … provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now