Datagrid: Option Strict On disallows late binding -- HELP

Discussion in 'ASP .Net' started by Owen Mortensen, Mar 10, 2006.

  1. (This code was working in 1.1 VS2003. After upgrade to VS2005,

    in the aspx file:

    <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    CellPadding="0" CellSpacing="1" Font-Size="Small" BackColor="Transparent"
    BorderStyle="None" BorderColor="#CCCCFF"
    DataSource=<%# buildInstrumentListDataGrid(container.dataitem("CatID"))%>>

    I get the error: Option Strict On disallows late binding

    What item is being late-bound? And how do I not late-bind it?

    Here's the function:

    Function buildInstrumentListDataGrid(ByVal CatID As String) As DataTable
    Dim lp_survey_Connect As New dBUtils("sConnectLPSurvey")
    Dim strInstrSQLQuery As String
    Dim objInstrDataSet As New DataSet

    strInstrSQLQuery = "SELECT InstID, InstName, CatID" & _
    " FROM InstrumentList" & _
    " WHERE CatID = " & CatID & " ORDER BY InstID"

    objInstrDataSet = lp_survey_Connect.GetDataSet(strInstrSQLQuery, False)

    Return objInstrDataSet.Tables(0)

    End Function

    Owen Mortensen, Mar 10, 2006
    1. Advertisements

  2. container.dataitem("CatID") does not return a string - it returns an object.
    You are not explicitly casting it to a string, so that is your problem.
    Marina Levit [MVP], Mar 10, 2006
    1. Advertisements

  3. OK. I don't know how to do that?

    I don't see "container.dataitem" anywhere....


    Owen Mortensen, Mar 10, 2006
  4. So, I changed container.dataitem("CatID") to
    container.dataitem("CatID").ToString() ... still get the same error. I do
    not know how this construct works: something I copied out of a book.... Is
    there an explanation somewhere documented?


    Owen Mortensen, Mar 10, 2006
  5. Well, this was one spot where I could see this being a problem - you did not
    tell us what line number is actually causing the compile time error, or
    whether or not you are using code behind.
    I am sort of surprised that an upgrade to 2005 would cause this. I have not
    encountered any Option Strict differences when upgrading code.

    Marina Levit [MVP], Mar 10, 2006
  6. Sorry. I AM using code-behind. So the control directive looks like this:
    <%@ Control Language="vb" AutoEventWireup="false"
    Inherits="cwsBackOffice.lp_survey_display_edit" %>

    AND, the top of the code-behind file looks like this:
    Imports System.Data
    Imports System.Data.SqlClient
    Imports Functions

    Namespace cwsBackOffice
    Partial Class lp_survey_display_edit
    Inherits System.Web.UI.UserControl

    Any ideas?
    Owen Mortensen, Mar 10, 2006
  7. Doh!. The line causing the compile time error is the "<asp:datagrid...."
    Owen Mortensen, Mar 10, 2006
  8. I STILL do not know how to fix the error. Which part of the
    <asp:datagrid.... declaration is tossing the error and why? What type is it
    looking for?

    Owen Mortensen, Mar 13, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.