dba123
asked on
System.InvalidCastException: Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'.
I'm not sure why I get this in my VB.NET 2.0 project. In my DataGrid I have:
<asp:TemplateColumn HeaderText="Phone">
<ItemStyle Wrap="False" HorizontalAlign="Left" CssClass="datagridcell" />
<ItemTemplate>
<nobr>
<a href="<%=GetClickToDialUrl %>?ClickTo Dial=81<%# StripPhone (CStr(CTyp e(Containe r.DataItem , System.Data.DataRow)("Phon e")))%>" target="ClickToDialFrame">
<%#FormatPhoneNumber(CStr( CType(Cont ainer.Data Item, System.Data.DataRow)("Phon e")))%>
</a>
</nobr>
</ItemTemplate>
</asp:TemplateColumn>
System.InvalidCastExceptio n: Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'.
<asp:TemplateColumn HeaderText="Phone">
<ItemStyle Wrap="False" HorizontalAlign="Left" CssClass="datagridcell" />
<ItemTemplate>
<nobr>
<a href="<%=GetClickToDialUrl
<%#FormatPhoneNumber(CStr(
</a>
</nobr>
</ItemTemplate>
</asp:TemplateColumn>
System.InvalidCastExceptio
Try to use "Container.DataItem.Row" replacing "Container.DataItem". Example:
...<a href="<%=GetClickToDialUrl %>?ClickTo Dial=81<%# StripPhone (CStr(CTyp e(Containe r.DataItem .Row, System.Data.DataRow)("Phon e")))%>" target="ClickToDialFrame">
<%#FormatPhoneNumber(CStr( CType(Cont ainer.Data Item.Row, System.Data.DataRow)("Phon e")))%>...
...<a href="<%=GetClickToDialUrl
<%#FormatPhoneNumber(CStr(
ASKER
>>>Any reason why you can't just use
<a href="<%=GetClickToDialUrl %>?ClickTo Dial=81<%# StripPhone (DataBinde r.Eval(Con tainer.Dat aItem, "PHONE"))%>" target="ClickToDialFrame">
Sent as an object to StripPhone, which then casts it to a string?
No, because OptionExplicit is required to be ON with .NET 2.0. So if you were doing C#, this issue is one I would have already had workikng because C# requires this. But since it's VB.NET I'm coming across this shit now. So with Option Explicit On, no you can't do it that way. And it's a good thing to have Option Explicit on. You shouldn't turn that off. Therefore I have to cast this crap like this.
<a href="<%=GetClickToDialUrl
Sent as an object to StripPhone, which then casts it to a string?
No, because OptionExplicit is required to be ON with .NET 2.0. So if you were doing C#, this issue is one I would have already had workikng because C# requires this. But since it's VB.NET I'm coming across this shit now. So with Option Explicit On, no you can't do it that way. And it's a good thing to have Option Explicit on. You shouldn't turn that off. Therefore I have to cast this crap like this.
ASKER
can you tell I hate VB....yes.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
lol - def yes, altho, I haven't turned off explicit, and it worked in my code last night without issue which was 2.0
(I prefer c# as well.)
(I prefer c# as well.)
ASKER
>>>Try to use "Container.DataItem.Row" replacing "Container.DataItem".
No, again same point
Option Strict On disallows late binding.
So that's a VB.NET thing. If you were to code this in C#, you would not have these problems.
No, again same point
Option Strict On disallows late binding.
So that's a VB.NET thing. If you were to code this in C#, you would not have these problems.
Doubt you can give yourself pts tho...
Happy to close with pts refund.
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
Vee_Mod
Community Support Moderator
<a href="<%=GetClickToDialUrl
DataBinder.Eval(Container.
)%>" target="ClickToDialFrame">
Sent as an object to StripPhone, which then casts it to a string?