[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

System.InvalidCastException: Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'.

Posted on 2007-10-05
11
Medium Priority
?
6,315 Views
Last Modified: 2008-01-09
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%>?ClickToDial=81<%#StripPhone(CStr(CType(Container.DataItem, System.Data.DataRow)("Phone")))%>" target="ClickToDialFrame">
                        <%#FormatPhoneNumber(CStr(CType(Container.DataItem, System.Data.DataRow)("Phone")))%>
          </a>
            </nobr>
      </ItemTemplate>
</asp:TemplateColumn>

System.InvalidCastException: Unable to cast object of type 'System.Data.DataRowView' to type 'System.Data.DataRow'.


0
Comment
Question by:dba123
10 Comments
 
LVL 7

Expert Comment

by:SimonBlake
ID: 20022124
Any reason why you can't just use

<a  href="<%=GetClickToDialUrl%>?ClickToDial=81<%#StripPhone(

DataBinder.Eval(Container.DataItem, "PHONE")

)%>" target="ClickToDialFrame">

Sent as an object to StripPhone, which then casts it to a string?
0
 
LVL 5

Expert Comment

by:-Thespian-
ID: 20022150
Try to use "Container.DataItem.Row" replacing "Container.DataItem". Example:
...<a  href="<%=GetClickToDialUrl%>?ClickToDial=81<%#StripPhone(CStr(CType(Container.DataItem.Row, System.Data.DataRow)("Phone")))%>" target="ClickToDialFrame">
                        <%#FormatPhoneNumber(CStr(CType(Container.DataItem.Row, System.Data.DataRow)("Phone")))%>...
0
 
LVL 1

Author Comment

by:dba123
ID: 20022207
>>>Any reason why you can't just use
<a  href="<%=GetClickToDialUrl%>?ClickToDial=81<%#StripPhone(DataBinder.Eval(Container.DataItem, "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.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:dba123
ID: 20022210
can you tell I hate VB....yes.
0
 
LVL 1

Accepted Solution

by:
dba123 earned 0 total points
ID: 20022244
I fixed it I just changed it to Container.DataItem, System.Data.DataRowView for whatever odd reason
0
 
LVL 7

Expert Comment

by:SimonBlake
ID: 20022280
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.)
0
 
LVL 1

Author Comment

by:dba123
ID: 20022334
>>>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.
0
 
LVL 7

Expert Comment

by:SimonBlake
ID: 20022377
Doubt you can give yourself pts tho...
0
 
LVL 7

Expert Comment

by:SimonBlake
ID: 20030876
Happy to close with pts refund.
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20042907
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question