Eval returning a null when an int is expected

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
 
S

Steven Cheng[MSFT]

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.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top