473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Why can't cast

ad
I have a field name SexID, it store 1 for male, 2 for female.
I want to present male/ female in the DataGrid.

I convert the field to a template column and then use a tmeplate
expression
like this:

<%# ( (int) DataBinder.Eval(Container,"DataItem.SexID")) == 1 ? "male" :
"female" %>

But it result into a System.InvalidCastException.

How can I do?


(This method is from Rick Strahl)

Nov 17 '05 #1
4 2178
<%# ( DataBinder.Eval(Container,"DataItem.SexID").ToStri ng() == "1" ?
"male" :
"female" %>

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:eM*************@TK2MSFTNGP09.phx.gbl...
I have a field name SexID, it store 1 for male, 2 for female.
I want to present male/ female in the DataGrid.

I convert the field to a template column and then use a tmeplate
expression
like this:

<%# ( (int) DataBinder.Eval(Container,"DataItem.SexID")) == 1 ? "male" :
"female" %>

But it result into a System.InvalidCastException.

How can I do?


(This method is from Rick Strahl)

Nov 17 '05 #2
<%# ( DataBinder.Eval(Container,"DataItem.SexID").ToStri ng() == "1" ?
"male" :
"female" %>

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:eM*************@TK2MSFTNGP09.phx.gbl...
I have a field name SexID, it store 1 for male, 2 for female.
I want to present male/ female in the DataGrid.

I convert the field to a template column and then use a tmeplate
expression
like this:

<%# ( (int) DataBinder.Eval(Container,"DataItem.SexID")) == 1 ? "male" :
"female" %>

But it result into a System.InvalidCastException.

How can I do?


(This method is from Rick Strahl)

Nov 17 '05 #3
ad <ad@wfes.tcc.edu.tw> wrote:
I have a field name SexID, it store 1 for male, 2 for female.
I want to present male/ female in the DataGrid.

I convert the field to a template column and then use a tmeplate
expression
like this:

<%# ( (int) DataBinder.Eval(Container,"DataItem.SexID")) == 1 ? "male" :
"female" %>

But it result into a System.InvalidCastException.

How can I do?


Find out what type it *actually* is at runtime (once, in a debugger)
and then cast to that. Unless you change the type of the column, it
should always be the same type.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
ad <ad@wfes.tcc.edu.tw> wrote:
I have a field name SexID, it store 1 for male, 2 for female.
I want to present male/ female in the DataGrid.

I convert the field to a template column and then use a tmeplate
expression
like this:

<%# ( (int) DataBinder.Eval(Container,"DataItem.SexID")) == 1 ? "male" :
"female" %>

But it result into a System.InvalidCastException.

How can I do?


Find out what type it *actually* is at runtime (once, in a debugger)
and then cast to that. Unless you change the type of the column, it
should always be the same type.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

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

Similar topics

18
by: Graham Nicholls | last post by:
Hi. I'm having some fun with numbers. I've extraced an image sizes from a jpeg file img_x,img_y=image.getsize() then I'm trying to use those sizes to scale the image, but because python...
1
by: Jonathan | last post by:
At the moment I have 3 files: a small XML instance document, a schema (which the .xml validates against fine) and a work-in-progress .xsl. (posted below) The problem is that I cannot get the...
3
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
6
by: Lore Leunoeg | last post by:
Hello I derived a class MyControl from the Control class. Public Class MyControl Inherits Control Sub New() MyBase.New() End Sub End Class
16
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
11
by: Dinsdale | last post by:
I am trying to determine what the current cast of an object is. Essentially, if I use GetType, it always returns the original type of the object created but I want to know what the current cast of...
17
by: arnuld | last post by:
I have checked the FAQ: http://c-faq.com/malloc/mallocnocast.html FAQ discusses a special case when programmer has forgotten to do #include <stdlib.h>. I am including this header and I am not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.