473,608 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange problem

I have a class method which takes integer as parameter...whe n i call the
method as shown below i get this error message: Specified cast is not valid

<td><%# bs.getPriority( (int)DataBinder .Eval(Container .DataItem,
"Priority") )%></td>

When i print the DataItem "Priority" it shows an integer value, but for some
reason the method does not like value.. if i call this method like ->
bs.getPriortiy( 3); it works fine.

In the database i have a field called "Priority" int type...

The method works fine when i call it in DataItemBound method..

any idea?
Nov 18 '05 #1
5 2037
Hi,

Try using

int.Parse(DataB inder.Eval(Cont ainer.DataItem, "Priority") )

DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com

Nov 18 '05 #2
Tod thank you so much :) it worked..

still confused why one of them works not the other as shown below:
<TD><%# bs.getCampusNam e((int)DataBind er.Eval(Contain er.DataItem,
"CampusID") )%></TD>

<td><%# bs.getCampusNam e((int.Parse(Da taBinder.Eval(C ontainer.DataIt em,
"Priority")))%> </td>

both CampusID and Priority is same type of value..

Many Thanks again.
"Tod Birdsall" wrote:
Hi,

Try using

int.Parse(DataB inder.Eval(Cont ainer.DataItem, "Priority") )

DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com

Nov 18 '05 #3
Sorry that did not solve the problem... :( i am getting this error message
now:

The best overloaded method match for 'int.Parse(stri ng)' has some invalid
arguments

"Tod Birdsall" wrote:
Hi,

Try using

int.Parse(DataB inder.Eval(Cont ainer.DataItem, "Priority") )

DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com

Nov 18 '05 #4
Acutally, DataBinder.Eval returns an object unless you pass a third
parameter, a format specifier, i.e.

DataBinder.Eval (Container.Data Item, "Priority", "{0:d}")

Otherwise you get an object reference back, in which case you could
use Convert.ToInt32

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 9 Nov 2004 07:38:03 -0800, "huzz"
<hu**@discussio ns.microsoft.co m> wrote:
Sorry that did not solve the problem... :( i am getting this error message
now:

The best overloaded method match for 'int.Parse(stri ng)' has some invalid
arguments

"Tod Birdsall" wrote:
Hi,

Try using

int.Parse(DataB inder.Eval(Cont ainer.DataItem, "Priority") )

DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com


Nov 18 '05 #5
Hi,

Scott is correct. Sorry for the mis-information.

I tried to reproduce your error message. I created a function in the
code behind like so:

protected string GetRemainderInE scrow(decimal approvedAmount, object
paidAmount)

I then called the method from the aspx page using the following code :

<%# GetRemainderInE scrow( (decimal)DataBi nder.Eval(Conta iner,
"DataItem.Appro vedAmount"), DataBinder.Eval (Container, "DataItem.Paid" )
) %>

The code worked as it should. If you have control over the
'bs.getPriority ' method, try allowing an object to be passed instead of
an integer value type. If that doesn't work. If that still does not
work, copy and paste the exact error message and Stack Trace.
Tod Birdsall, MCP
http://tod1d.blogspot.com

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2303
by: Rob Ristroph | last post by:
Hi, It's pretty unhelpful to post "I have a huge piece of code that crashes in strange places, what's the problem?" but that's basically my problem and I really am at my wit's end. The piece of code in question always crashes in an STL operation such as a vector.push_back, but the location of the crash changes as I change how various parts are handled in memory, i.e., make some things dynamically allocated instead of new'd. I know...
2
1957
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which catches all exceptions that have not be handled at a higher level. The catch block cleans up and...
25
3715
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
2
1778
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions to perform some calculations. After some number of iterations, randomly, I'll get an uncaught NullValueException error on one of these calls, as if the class name is being treated as an object reference and is null. Here is some psuedo-code to...
1
3758
by: Sam Kong | last post by:
Hello! Recently I had a strange problem with Visual C# 2005 beta 1. When I ran(F5 key) a program, <#if DEBUG> statement was not working. It ran as RELEASE mode. So I had to manually define DEBUG to make #if DEBUG work. When I first started the project, this problem didn't exist. The problem started to exist in the middle of doing the project. Today, I decided to figure out what went wrong.
8
6682
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and contains a few controls anchored to the sides of the form. "frmChild" inherits from "frmBase"... and the controls appear on the inherited form as expected. However things start going wrong when I place addition controls on the "frmChild" form. When I...
11
2580
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating temperatures. T = 20 degrees at all times.... The 2D T-array looks like this:
12
2259
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
8
5291
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
5
2426
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7 and its clones I encounter a strange problem where I can hear clicking sound non-stop (like the page is being reloaded non- stop), whereas the page is not reloading.
0
7987
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8472
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8464
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8130
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8324
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4015
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1318
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.