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 asp.net 1.1 VS2003. After upgrade to VS2005,
    chokes):

    in the aspx file:

    <ItemTemplate>
    <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    HeaderStyle-Font-Bold="True"
    CellPadding="0" CellSpacing="1" Font-Size="Small" BackColor="Transparent"
    ForeColor="Black"
    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)
    lp_survey_Connect.Dispose()

    Return objInstrDataSet.Tables(0)

    End Function

    Thanks,








    --------------------------------------------------------------------------------
    Owen
    Owen Mortensen, Mar 10, 2006
    #1
    1. Advertising

  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.

    "Owen Mortensen" <> wrote in message
    news:...
    > (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    > chokes):
    >
    > in the aspx file:
    >
    > <ItemTemplate>
    > <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    > HeaderStyle-Font-Bold="True"
    > CellPadding="0" CellSpacing="1" Font-Size="Small" BackColor="Transparent"
    > ForeColor="Black"
    > 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)
    > lp_survey_Connect.Dispose()
    >
    > Return objInstrDataSet.Tables(0)
    >
    > End Function
    >
    > Thanks,
    >
    >
    >
    >
    >
    >
    >
    >
    > --------------------------------------------------------------------------------
    > Owen
    >
    Marina Levit [MVP], Mar 10, 2006
    #2
    1. Advertising

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

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

    ?

    "Marina Levit [MVP]" <> wrote in message
    news:...
    > 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.
    >
    > "Owen Mortensen" <> wrote in message
    > news:...
    >> (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    >> chokes):
    >>
    >> in the aspx file:
    >>
    >> <ItemTemplate>
    >> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    >> HeaderStyle-Font-Bold="True"
    >> CellPadding="0" CellSpacing="1" Font-Size="Small" BackColor="Transparent"
    >> ForeColor="Black"
    >> 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)
    >> lp_survey_Connect.Dispose()
    >>
    >> Return objInstrDataSet.Tables(0)
    >>
    >> End Function
    >>
    >> Thanks,
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> --------------------------------------------------------------------------------
    >> Owen
    >>

    >
    >
    Owen Mortensen, Mar 10, 2006
    #3
  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

    "Marina Levit [MVP]" <> wrote in message
    news:...
    > 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.
    >
    > "Owen Mortensen" <> wrote in message
    > news:...
    >> (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    >> chokes):
    >>
    >> in the aspx file:
    >>
    >> <ItemTemplate>
    >> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    >> HeaderStyle-Font-Bold="True"
    >> CellPadding="0" CellSpacing="1" Font-Size="Small" BackColor="Transparent"
    >> ForeColor="Black"
    >> 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)
    >> lp_survey_Connect.Dispose()
    >>
    >> Return objInstrDataSet.Tables(0)
    >>
    >> End Function
    >>
    >> Thanks,
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> --------------------------------------------------------------------------------
    >> Owen
    >>

    >
    >
    Owen Mortensen, Mar 10, 2006
    #4
  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.

    "Owen Mortensen" <> wrote in message
    news:e$...
    > 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
    >
    > "Marina Levit [MVP]" <> wrote in message
    > news:...
    >> 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.
    >>
    >> "Owen Mortensen" <> wrote in message
    >> news:...
    >>> (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    >>> chokes):
    >>>
    >>> in the aspx file:
    >>>
    >>> <ItemTemplate>
    >>> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    >>> HeaderStyle-Font-Bold="True"
    >>> CellPadding="0" CellSpacing="1" Font-Size="Small"
    >>> BackColor="Transparent" ForeColor="Black"
    >>> 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)
    >>> lp_survey_Connect.Dispose()
    >>>
    >>> Return objInstrDataSet.Tables(0)
    >>>
    >>> End Function
    >>>
    >>> Thanks,
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> --------------------------------------------------------------------------------
    >>> Owen
    >>>

    >>
    >>

    >
    >
    Marina Levit [MVP], Mar 10, 2006
    #5
  6. Sorry. I AM using code-behind. So the control directive looks like this:
    <%@ Control Language="vb" AutoEventWireup="false"
    CodeFile="lp_survey_display_edit.ascx.vb"
    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?
    Thanks,
    Owen

    "Marina Levit [MVP]" <> wrote in message
    news:e%...
    > 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.
    >
    > "Owen Mortensen" <> wrote in message
    > news:e$...
    >> 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
    >>
    >> "Marina Levit [MVP]" <> wrote in message
    >> news:...
    >>> 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.
    >>>
    >>> "Owen Mortensen" <> wrote in message
    >>> news:...
    >>>> (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    >>>> chokes):
    >>>>
    >>>> in the aspx file:
    >>>>
    >>>> <ItemTemplate>
    >>>> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    >>>> HeaderStyle-Font-Bold="True"
    >>>> CellPadding="0" CellSpacing="1" Font-Size="Small"
    >>>> BackColor="Transparent" ForeColor="Black"
    >>>> 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)
    >>>> lp_survey_Connect.Dispose()
    >>>>
    >>>> Return objInstrDataSet.Tables(0)
    >>>>
    >>>> End Function
    >>>>
    >>>> Thanks,
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> --------------------------------------------------------------------------------
    >>>> Owen
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Owen Mortensen, Mar 10, 2006
    #6
  7. Doh!. The line causing the compile time error is the "<asp:datagrid...."
    line

    "Marina Levit [MVP]" <> wrote in message
    news:e%...
    > 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.
    >
    > "Owen Mortensen" <> wrote in message
    > news:e$...
    >> 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
    >>
    >> "Marina Levit [MVP]" <> wrote in message
    >> news:...
    >>> 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.
    >>>
    >>> "Owen Mortensen" <> wrote in message
    >>> news:...
    >>>> (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    >>>> chokes):
    >>>>
    >>>> in the aspx file:
    >>>>
    >>>> <ItemTemplate>
    >>>> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    >>>> HeaderStyle-Font-Bold="True"
    >>>> CellPadding="0" CellSpacing="1" Font-Size="Small"
    >>>> BackColor="Transparent" ForeColor="Black"
    >>>> 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)
    >>>> lp_survey_Connect.Dispose()
    >>>>
    >>>> Return objInstrDataSet.Tables(0)
    >>>>
    >>>> End Function
    >>>>
    >>>> Thanks,
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> --------------------------------------------------------------------------------
    >>>> Owen
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Owen Mortensen, Mar 10, 2006
    #7
  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?

    HELP?

    "Owen Mortensen" <> wrote in message
    news:...
    > Doh!. The line causing the compile time error is the "<asp:datagrid...."
    > line
    >
    > "Marina Levit [MVP]" <> wrote in message
    > news:e%...
    >> 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.
    >>
    >> "Owen Mortensen" <> wrote in message
    >> news:e$...
    >>> 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
    >>>
    >>> "Marina Levit [MVP]" <> wrote in message
    >>> news:...
    >>>> 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.
    >>>>
    >>>> "Owen Mortensen" <> wrote in message
    >>>> news:...
    >>>>> (This code was working in asp.net 1.1 VS2003. After upgrade to VS2005,
    >>>>> chokes):
    >>>>>
    >>>>> in the aspx file:
    >>>>>
    >>>>> <ItemTemplate>
    >>>>> <asp:datagrid id="dg_instr" runat="server" AutoGenerateColumns="False"
    >>>>> HeaderStyle-Font-Bold="True"
    >>>>> CellPadding="0" CellSpacing="1" Font-Size="Small"
    >>>>> BackColor="Transparent" ForeColor="Black"
    >>>>> 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)
    >>>>> lp_survey_Connect.Dispose()
    >>>>>
    >>>>> Return objInstrDataSet.Tables(0)
    >>>>>
    >>>>> End Function
    >>>>>
    >>>>> Thanks,
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>> --------------------------------------------------------------------------------
    >>>>> Owen
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Owen Mortensen, Mar 13, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karl Lang
    Replies:
    1
    Views:
    885
    Karl Lang
    Jun 1, 2004
  2. Ryan McLean

    Option Strict On disallows late binding.

    Ryan McLean, Jun 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    10,321
    mikeb
    Jun 14, 2004
  3. Adotek
    Replies:
    1
    Views:
    426
    Bruno Alexandre
    Oct 3, 2006
  4. Chris Davey via .NET 247

    Option Strict On disallows late binding

    Chris Davey via .NET 247, Apr 6, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    154
    Brock Allen
    Apr 6, 2005
  5. Seema
    Replies:
    1
    Views:
    840
    Arne Vajhøj
    Jan 25, 2012
Loading...

Share This Page