I have a formview with a dropdownlist created dynamically. i want to determine whether the dropdownlist was clicked. the code is written in the FormView1_DataBound method.
I get the following error in the line below that is in italics and underlined:
Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.
Here is my code:
ddl_iFullname =New DropDownList
ddl_iFullname.DataSource = ObjectDataSource3
AddHandler ddl_iFullname.SelectedIndexChanged, AddressOf Me.Ddl_SelectedIndexChanged
Dim myddl As String = CType(sender, DropDownList).Text
myddl = myddl.ToUpper() 'Select Case myddl Case "ddl_iFullname"
Response.Write("dropdownlist clicked") End Select
Sender is object of System.Web.UI.WebControls.FormView type, so it cannot be casted on System.Web.UI.WebControls.DropDownList. Try to use FindControl method of FormView. Retype sender e. g. on WebControl and call FindControl method with parameter of DropDownList ID.