Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Drop Down List Selected Value

Status
Not open for further replies.

SaturnSeven

Programmer
Aug 4, 2005
40
GB
I have managed to loop through all Drop Down Lists on my aspx page, but I need to get the Selected Value of each by using the control reference in the loop.

For Each cntrl As Control In Form.Controls
If TypeOf cntrl Is DropDownList Then
lblResults.Text &= cntrl.ClientID & " " & "<br />"
lblResults.text &= ???cntrl.SelectedValue???
End If
Next

Any help/advise greatly apreciated
 
you will have to cast cntrl to a drop down list
Code:
DirectCast(cntrl, DropDownList)  OR  
CType(ctls, DropDownList)   OR   
TryCast(ctls, DropDownList)
 
SaturnSeven said:
but I need to get the Selected Value of each by...

There is only ever one selected value of a drop down list.

For Each cntrl As Control In Form.Controls
If TypeOf cntrl Is DropDownList Then
lblResults.Text &= cntrl.ClientID & " " & "<br />"
'another foreach loop here (needs proper VB conversion)
Code:
            foreach (ListItem li in ddlDropDownList.Items)
            {
                lblResults.Text += li.Value + " - " + li.Text;
            }
End If
Next
 
oh poo, dont know what i was thinking.... sorry please disregard post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top