Why can't cast

  • Thread starter Thread starter ad
  • Start date Start date
A

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)
 
ad said:
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.
 
Back
Top