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 .
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
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.