Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 143165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:03:08+00:00 2026-05-11T08:03:08+00:00

I have a asp:BoundColumn with DateTime? data (i’ll call it column X) in the

  • 0

I have a asp:BoundColumn with DateTime? data (i’ll call it column X) in the asp:GridView. I loop through all the rows in the grid, and cast the .Text property to column X to DateTime (i need this to do some checking and change the cell background color if needed).

I have 2 options:

  1. wrap the cast in try/catch … handle FormatException (in case column X gets rendered with some junk in it) … and work only with valid DateTime values.

  2. check the column X to make sure it’s in the correct format (how?) before casing, and only cast if format is ok.

Which approach should i take, and why?

Thank you.

p.s. 1 up-vote for all explanations, accepted answer for TryParse

Edit2: even though i used TryParse, I’ve unchecked the accepted answer to keep the discussion going.

My ‘good data’/’bad data’ ratio is about 2/1 – this means lots of bad input

I’ll re-accept the answer in a couple of days, if nothing else comes up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:03:09+00:00Added an answer on May 11, 2026 at 8:03 am

    You could do the 2nd option. DateTime.TryParse can help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net app where I am using gridview for data showing, editing and
I have a standard ASP.NET GridView and I'd like the first column (a emplateField
I have Asp.net application that implemented with Dynamic Data technology. All data from my
I have asp:GridView displaying client requests using asp:SqlDataSource . I want to limit displayed
I have a rather simple problem with ASP.NET. I have a grid view with
I have ASP.NET site. At one point postback is triggered and some data is
This is all asp.net c#. I have an enum public enum ControlSelectionType { NotApplicable
I have a DataGrid in ASP.NET 2.0 with the following column in it: <ASP:TEMPLATECOLUMN>
I have asp.net chart intervel issue. I am feed data to chart like below
I have a block of code, that essentially is this: <asp:DataGrid> <Columns> ... <asp:BoundColumn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.