Datagrid: Option Strict On disallows late binding -- HELP

O

Owen Mortensen

(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,
 
M

Marina Levit [MVP]

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.
 
O

Owen Mortensen

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

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

?

Marina Levit said:
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.
 
O

Owen Mortensen

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 said:
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.
 
M

Marina Levit [MVP]

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 said:
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
 
O

Owen Mortensen

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
 
O

Owen Mortensen

Doh!. The line causing the compile time error is the "<asp:datagrid...."
line
 
O

Owen Mortensen

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?
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top