0

I have a simple web for that has a dropdown list and a button on the form. The dropdown list is bound to a table in my database and holds three values with idents between 1 and 3 (Weekly, Monthly, Please Select).

I have set my datasource to pull back item 3 (Please Select) as the first item in the dropdown list to prompt the user to select an option. Items 1 & 2 have data assigned to them and this pulls back the relevent data for these options.

Here is my problem. I need to hide my button when the page loads until the user selects item 1 or 2 and would like the button to be hidden of option 3 is selected. I have tried to complete this in my page load event and the code for the dropdown list but i cannot seem to get this to work.

    If IsNumeric(DropDownList1.SelectedValue) = 3 Then
        btnAddAgendaTemplate.Visible = False
    End If
Gilles 'SO- stop being evil'
  • 92,660
  • 35
  • 189
  • 229
Betty
  • 551
  • 1
  • 10
  • 24

3 Answers3

0

Change the compare to:

   If DropDownList1.SelectedValue = "3" Then
        btnAddAgendaTemplate.Visible = False
    End If

The function IsNumberic just confirm if this is number or not and not convert it to number, and not compare it with the 3. Now the SelectedValue is a string, so direct compare it with the "3", no reason to convert it to number as it is.

Aristos
  • 63,580
  • 14
  • 112
  • 146
0

Edit: (based on the comment)
In Selected Index changed event for the drop down check for the selectedvalue to be 3 and process accordingly

Suppose your selectedIndexChanged event is like this in your code behind:

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
 If DropDownList1.SelectedValue.Equals("3") Then
     btnAddAgendaTemplate.Visible = False
 End If
End Sub
Habib
  • 205,061
  • 27
  • 376
  • 407
  • Hi Habib, if i just add btnAddAgendaTemplate.Visible = False to the page load event, this hides the button fully. When my user selects option 1 or option two they have no submit button. I am just wanting to hide the button when a user has selected option 3. And three is the default option when a user opens the page. – Betty Apr 18 '12 at 09:10
  • @Betty, in that case you need to change only the selectedindexchanged event, I have update the answer, check now – Habib Apr 18 '12 at 09:20
0

In page load event write following code

If Not Page.IsPostBack() Then
//Set default value in drop down list as 3
End

and

Write selection index changed event of drop down and write following code inside it.

If DropDownList1.SelectedValue = "3" Then
    btnAddAgendaTemplate.Visible = False
ELSE
    btnAddAgendaTemplate.Visible = True
END
Gilles 'SO- stop being evil'
  • 92,660
  • 35
  • 189
  • 229
Sanket K
  • 11
  • 5
  • You'll also want to make sure that the autopostback property for your drop down list is set to 'True'. – A. Still Apr 18 '12 at 15:37
  • And you'll need to set the visible property of the button to False in the designer, so that it isn't visible at the beginning. – A. Still Apr 18 '12 at 15:48