Hi,
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 DropDownListddl_iFullname.ID =
"ddl_iFullname"ddl_iFullname.DataSource = ObjectDataSource3
ddl_iFullname.DataTextField =
"fullname"ddl_iFullname.DataValueField =
"id" ddl_iFullname.DataBind()ddl_iFullname.AutoPostBack =
TrueAddHandler ddl_iFullname.SelectedIndexChanged, AddressOf Me.Ddl_SelectedIndexChanged
plc_fullname.Controls.Add(ddl_iFullname)
Dim myddl As String = CType(sender, DropDownList).Text
myddl = myddl.ToUpper() '
Select Case myddl Case "ddl_iFullname"Response.Write(
"dropdownlist clicked") End Select
![]() |
0 |
![]() |
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.
![]() |
0 |
![]() |