0

Currently, I have received a piece of code to work with. There is a dropdownlist which displays the grade/year of student (Prep - Year 12). The "Prep" value is added to the Dropdownlist by this code, I believe:

Public Sub PopulateGradeWithPrep(ByRef ddlYear As DropDownList, ByVal intMax As Integer, ByVal intMin As Integer)
            Dim iLoop As Integer

            'populate year ddl

            If ddlYear.Items.Count = 0 Then
                For iLoop = intMin To intMax
                    If (iLoop = 0) Then
                        ddlYear.Items.Add(New ListItem("Prep", CStr(iLoop)))
                    Else
                        ddlYear.Items.Add(CStr(iLoop))
                    End If
                Next
            End If
        End Sub

The name of the dropdownlist is YearLevelAdmission, the is a code to populate the data from the above code to it which is this:

 Private Sub PopulateScreenList(ByVal strYearLevelAdmission As String)
        'Populate year level admission
        slco.PopulateGradeWithPrep(ddlYearLevelAdmission, 12, 0)
        'populate year level admission value
        If Not slco.IsStringBlank(strYearLevelAdmission) Then
            slco.SelectItemInDDList(ddlYearLevelAdmission, strYearLevelAdmission)
        End If

slco is Module Common. The First code was written in .vb file.

Those 2 code above are given to me and I am using code behind, trying to select the value of "Prep", then some of the panel will be invisible. This is my code:

If ddlYearLevelAdmission.SelectedValue ="Prep" Then
panel1.visible= false
panel2.visible = false
Else
panel1.visible = true
panel2.visible = true
End If

The problem is when I select Prep, there is auto post back but nothing change, the two panels are still there. I have been stuck for a day already.

Help is really appreciated

Cheers

1 Answer 1

0

When you add "Prep" to DropDown you are actually adding a ListItem, not a string. I believe you ment to add a string - instead of

ddlYear.Items.Add(New ListItem("Prep", CStr(iLoop)))

you should write

ddlYear.Items.Add("Prep")
1
  • Then we are looking at wrong code. Could you please put a breakpoint to If ddlYearLevelAdmission.SelectedValue ="Prep" Then and verify type and value of "SelectedValue"? Feb 28, 2012 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.