Conversion errors from .NET 2.0 ASP.NET...

B

Brian Henry

Ok how do I fix this... it worked in ASP.NET 1.1, in 2.0 it says

Error 3 Option Strict On disallows implicit conversions from 'Object' to
'String'.

here is the part of code it is giving this error on, its an item template
from a data grid... the line that has the error underlined is
"<%#Eval("filename")%>" which use to be
<%#DataBinder.Eval(Container,DataItem,"filename")%> but in ASP.NET 2.0 you
can shorten it to just eval of course... but neither of them lets you use
the item with out an object error...

<ItemTemplate>

<tr>

<td style="border-bottom: 1px solid #D1D1D1; padding-left: 2px;
padding-right: 2px; padding-top: 5px; padding-bottom: 5px"

width="16">

<font size="1" face="Verdana" color="#333333"><img
src='../images/filetypes/<%#
SecureEmail.Functions.GetAttachmentIconType(DataBinder.Eval(Container.DataItem,
"filename"))%>' alt="Attachment"></font></td>

<td style="border-bottom: 1px solid #D1D1D1; padding-left: 2px;
padding-right: 2px; padding-top: 5px; padding-bottom: 5px"

width="100%">

<font size="1" face="Verdana" color="#333333"><b>

<%#Eval("filename")%>

</b>(<%#SecureEmail.Functions.FormatFileSize(CInt(DataBinder.Eval(Container.DataItem,
"filesize")))%>)</font></td>

<td style="border-bottom: 1px solid #D1D1D1; padding-left: 2px;
padding-right: 2px; padding-top: 5px; padding-bottom: 5px"

align="right" width="50%" >

<font size="1" face="Verdana" color="#003399"><img border="0"
src="../images/DOWNLOAD.gif" width="12" height="12" alt="Download">&nbsp;<a
href ='MessageViewer.aspx?messageid=<%# DataBinder.Eval(Container.DataItem,
"MessageID") %>&attachmentID=<%# DataBinder.Eval(Container.DataItem,
"AttachmentID")%>&filename=<%# DataBinder.Eval(Container.DataItem,
"filename") %> ' >Save

File to Computer</a></font></td>

</tr>

</ItemTemplate>
 
B

Brian Henry

another example from a data repeater....

<ItemTemplate>

<%#PriorityStateIcon(CInt(Eval("Priority")))%>

</ItemTemplate>



says...Error 3 Option Strict On disallows implicit conversions from 'Object'
to 'String'. C:\SecurePages\Search.aspx 180 15 http://localhost/rsmn/


and this is the function its calling



Function PriorityStateIcon(byval state as integer) as string

Select case state

case 1

return "<img height='16px' width='16px' src = '../images/prio-low.gif'
ALT=""Low priority"">"


case 2

return string.empty


case 3

return "<img height='16px' width='16px' src = '../images/prio-high.gif'
ALT=""High priority"">"

end select

Return String.Empty

End Function
 
G

Greg Burns

Brian,

I tried to set up an simple example to see that error happen, but I can't
duplicate it.

Here is the code I am testing with:

<asp:DataGrid id="grid" runat="server" AutoGenerateColumns=false>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="label1" runat="server"
Text='<%#PriorityStateIcon(CInt(Eval("Priority")))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>


Option Strict On

Partial Class _Default
Inherits System.Web.UI.Page
Function PriorityStateIcon(ByVal state As Integer) As String

Select Case state

Case 1

Return "1"


Case 2

Return "2"

Case 3

Return "3"

End Select

Return String.Empty

End Function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim dt As New Data.DataTable("table1")

dt.Columns.Add("Priority", GetType(Integer))
Dim dr As Data.DataRow
dr = dt.NewRow
dr("Priority") = "1"
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Priority") = "2"
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Priority") = "3"
dt.Rows.Add(dr)

grid.DataSource = dt
grid.DataBind()
End Sub
End Class

I have Option Strict turned on as default in VS Studios options. I also
added it to the top of my codebehind file just to be sure. Have you done
more than that?

I am just beginning down this path myself (upgrading to 2.0 framework.) :(

Greg
 
B

Brian Henry

Option strict is on... I converted this project on load from .NET 1.1... and
it's been error heck... after conversion a 0 error solution in asp.net now
has 500 some errors... and has been heck trying to get through half them...
some of the documentation on them is the most vague documentation ive ever
seen...
 
G

Greg Burns

How did you deal the new XHTML requirement? It wanted me to manually fix
all my html! ahh!!!
 
B

Brian Henry

i switched the doc types back to HTML 4.1 to get around the XHTML
transitional requirements... not gona tackel that until i get this other
junk figured out... with XHTML turned on, It was in the 10,000 error range
after a full compile... and thought whoa... tag after tag after tag was an
error...
 
G

Greg Burns

I was hoping there was a wizard that would do this for us. It seems like a
perfect job for a computer, but insurmountable for the rest of us.

Greg
 
B

Brian Henry

yeah me too... if it knows there errors are there like "missing /" or "in
caps" why cant it fix that itself
 

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

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top