• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1207
  • Last Modified:

ASP.Net dropdownlist control. Item Selection and Autopostback

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 :-)
1 Solution
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: http://www.codetoad.com/javascript/enable_disable_form_element.asp
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


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now