Eval returning a null when an int is expected

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I'm binding to a column in a TemplateField. In some cases the join I have
returns a null for an int field. I would like to specify a default value
somehow so I don't end up with a null exception.

I'm binding the CurrentRating of the Rating control so I'm doing
Convert.ToInt32(Eval('MyField')). This of course throws an exception if the
value being returned is null.

Is there another means of binging to that property where either a null
doesn't matter or I can replace it with a 0?

Thanks,
Joe
 
Hi Joe,

Just some suggestions for databinding:

in the <%# %> expression, you can use helper function, for example:

Property='<%# MyFunction(Eval("propertyname")) %>'

this function can be defined in aspx inline or in code behind. Such
function can let you do some complex formating or customization on the raw
databound value.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Back
Top