Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
m trying to display images in datagrid....
 
<img alt=""  runat="server" src='<%# "GetImage.aspx?ID=" (DataBinder.Eval(Container.DataItem, "Image"))  %>' ID="Img1"/>
 
Exception:
cannot convert from type byte() to type integer()
any ideas??
Posted 28-Feb-13 2:47am
Edited 28-Feb-13 6:05am
v2
Comments
Sergey Alexandrovich Kryukov at 28-Feb-13 11:07am
   
Ideas? What do you mean by ideas? :-)
—SA
richcb at 28-Feb-13 11:09am
   
I have lots of ideas. I want to start a business one day and fly a spaceship to Jupiter and invent free energy.
Sandeep Mewara at 28-Feb-13 11:22am
   
Error and lines don't coincide. Some other code raising the issue.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is because there are not the types byte() or integer() in C#, and, in VB.NET, they can be the arrays of those integer values.
 
There are types byte, int and a lot more. "Conversion" you need is done by assignment. This is because the set of values if the type byte is a subset of that of the type int. You need type case to assign the value if int variable to byte variable.
 
As to arrays of different numeric types, they cannot be assigned compatible at all. Do I need to explain what would happen if such cast would be possible?
 
(I explained it in more general terms of sets of values, not ranges, because not all numeric types have ranges, floating-point types work differently and include Infinity and Not-a-Number values. Still, they have assignment compatibility rules. But integer types have ranges. "Range" is a bad, sloppy term which became a universally used computing jargon; correct term for set of values is "domain".)
 
Also, int and byte are actually alias names for System.Int32 and System.Byte. All numeric types have alias names, to make the code independent from the System namespace.
 
Please see:
http://msdn.microsoft.com/en-us/library/ae55hdtk%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms173105.aspx[^],
http://msdn.microsoft.com/en-us/library/s2dy91zy.aspx[^],
http://www.fmsinc.com/free/NewTips/NET/NETtip6.asp[^].
 
See also this CodeProject article: Cheat Sheet - Casting in VB.NET and C#[^].
 
What to do? Review the types of variables you use in your ASP.NET construct.
 
—SA
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 347
1 DamithSL 305
2 ridoy 278
3 OriginalGriff 224
4 George Jonsson 140
0 OriginalGriff 7,968
1 DamithSL 6,179
2 Sergey Alexandrovich Kryukov 5,524
3 Maciej Los 5,438
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100