ASP.NET 2.0 ProfessionalIf you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Hi;
I am trying to highlight rows in a gridview when the data (date/time) Column1 is older than the data (date/time) in Column2. these collomns can be empty (null) therefore it get this errow message :"Object cannot be cast from DBNull to other types"
I would be grateful if anyone help me with that. this is my code
where do you get the error????.. unless I missing something this looks ok...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question: http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof: http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Thanks Gonzalo for your reply,
I get the error on these lines: DateTime date1 = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "Column1"));
DateTime date2 = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "Column2"));
and i think because Column1 and Column2 contain empty cells(i.e. in the data source some time these columns should have empty cells and this cause the problem).
Well, you will get an error if you try to convert a blank value to datetime, optimize your code so that you convert to datetime only if the column has some value, avoid conversion in case of blank & null values.