Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Error in CType

Hi,

I want to access a control in a datalist and I type:

Dim txtbox as Textbox = CType(datalist.item.findcontrol("Name"), Textbox)

However, it shows me an error of this statement:

Value of type "System.Web.UI.Control" cannot be converted to "System.Windows.Forms"

Could anyone help me? I search almost the whole internet and it seems that no one has come across this problem!!!
[422 byte] By [THL] at [2007-11-11 7:05:35]
# 1 Re: Error in CType
If you have the line "Imports System.Windows.Forms" at the top of your code file, delete it. You may also want to look at your project's References in the Solution Explorer, and remove the reference to System.Windows.Forms, if present.
Phil Weber at 2007-11-11 23:14:00 >
# 2 Re: Error in CType
Thanks Phil Weber,

It works, but why the CType function will cast the object to "Imports System.Windows.Forms" instead of "System.Web.UI.Control"?
THL at 2007-11-11 23:15:06 >
# 3 Re: Error in CType
I'm not sure. It probably depends upon the order in which you add References/Imports statements.

P.S. -- I can't think of a good reason why one would need both System.Windows.Forms and System.Web.UI in the same project, can you?
Phil Weber at 2007-11-11 23:16:04 >