Option Strict On disallows late binding from Visual Studio 2005

If you get this surprise error after converting the asp.net project.
This is what you need to do

 Original
<%# Container.DataItem("ID"
) %>

Change to
CType(Container.DataItem, DataRowView)("ID"
).ToString

This solve your problem.

To set Option Strict in the integrated development environment (IDE)
On the Tools menu, choose Options.

Open the Projects and Solutions node.

Choose VB Defaults.

Modify the Option Strict setting.

To set Option Strict on the command line
Include the /optionstrict compiler option in the vbc command.

 

 

Suresh Behera

4 Comments

  • Or (assuming you are using ASP.NET 2 or above) you can leave Option Strict On, and just do:



    I hope this helps.

    Regards,

    David

  • Why not use Eval or Bind?

  • Or alternatively,
    DataBinder.Eval(Container.DataItem, "ID")

    Or, for ASP.NET 2.0:
    Eval("ID")

    Both of these will work even if the DataItem is not a DataRowView - for example, if you bind to a custom collection of business objects.

  • Or alternatively:
    DataBinder.Eval(Container.DataItem, "ID")

    Or, for ASP.NET 2.0:
    Eval("ID")

    Both of these will work even if the DataItem is not a DataRowView - for example, if you bind to a collection of custom business objects.

Comments have been disabled for this content.