Error in CType


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Error in CType

  1. #1
    Join Date
    Aug 2005
    Posts
    111

    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!!!

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Aug 2005
    Posts
    111
    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"?

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. CType travesty
    By matt Doig in forum .NET
    Replies: 12
    Last Post: 03-09-2002, 08:14 AM
  2. CType Conversion
    By Bart Ross in forum .NET
    Replies: 7
    Last Post: 09-05-2001, 07:53 PM
  3. Replies: 1
    Last Post: 03-11-2001, 02:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center