How to deal with exceptions in inline code

  • Thread starter Erik Funkenbusch
  • Start date
E

Erik Funkenbusch

Does anyone have any suggestions for how to deal with exceptions in inline
DataBinder code? For example, I want to convert a string to a date type,
but the string may contain non-date strings in rare occasions. This will
throw an invalid cast exception.

Any suggestions?
 
J

Jason Kester

On the .aspx:

<%# YourConversionMethod( DataBinder.Eval(Container.DataItem,
"YourColumn") )%>


and in the CodeBehind:

protected string YourConversionMethod(object item)
{
// cast, do whatever contitional processing you need to,
// and return a string for output.
}


Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 

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

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top