Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'.

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 DropDownList

ddl_iFullname.ID =

"ddl_iFullname"

ddl_iFullname.DataSource = ObjectDataSource3

ddl_iFullname.DataTextField =

"fullname"

ddl_iFullname.DataValueField =

"id"

ddl_iFullname.DataBind()

ddl_iFullname.AutoPostBack =

True

AddHandler 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
whisky
1/14/2007 10:49:11 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1285 Views

Similar Articles

[PageSpeed] 38

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
Marian
1/14/2007 11:30:22 AM
Reply:

Web resources about - Unable to cast object of type 'System.Web.UI.WebControls.FormView' to type 'System.Web.UI.WebControls.DropDownList'. - asp.net.presentation-controls


Resources last updated: 1/15/2016 10:54:23 PM