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 67923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:20:09+00:00 2026-05-10T19:20:09+00:00

I have a very simple ASP.Net page that acts as a front end for

  • 0

I have a very simple ASP.Net page that acts as a front end for a stored procedure. It just runs the procedure and shows the output using a gridview control: less than 40 lines of total code, including aspx markup. The stored procedure itself is very… volatile. It’s used for a number of purposes and the output format changes regularly.

The whole thing works great, because the gridview control doesn’t really need to care what columns the stored procedure returns: it just shows them on the page, which is exactly what I want.

However, the database this runs against has a number of datetime columns all over the place where the time portion isn’t really important- it’s always zeroed out. What I would like to be able to do is control the formatting of just the datetime columns in the gridview, without ever knowing precisely which columns those will be. Any time a column in the results has a datetime type, just apply a given format string that will trim off the time component.

I know I could convert to a varchar at the database, but I’d really don’t want to have to make developers care about formatting in the query and this belongs at the presentation level anyway. Any other ideas?


Finally got this working in an acceptable (or at least improved) way using this code:

Protected Sub OnRowDatabound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)     If e.Row.RowType = DataControlRowType.DataRow Then         Dim d As DateTime         For Each cell As TableCell In e.Row.Cells             If Date.TryParse(cell.Text, d) AndAlso d.TimeOfDay.Ticks = 0 Then                 cell.Text = d.ToShortDateString()             End If         Next cell     End If End Sub 
  • 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-10T19:20:10+00:00Added an answer on May 10, 2026 at 7:20 pm

    If you are auto generating the columns which it sounds like you are. The procedure for using the grids formatting is awful.

    You would need to loop through all the columns of the grid, probably in the databound event and apply a formatting expression to any column you find is a date column.

    If you are not auto generating and you are hadcoding columns in your grid you will also know alreayd which columns are date columns and you can apply the same format expression to that column. It’s something like {0:ddMMyyyy} but you will have to look it up as that’s probably not quite right.

    so to summarise hook into the databound event. loop through the column collection and ascertain if the column is a date column. I wonder how you might do this :). If you decide a column is a date column set its format expression.

    Voila

    ———————- EDIT

    Ok how about you write you method that returns the data from the proc to return a datatable. You can bind the datatable to your grid after formatting the data in the datatable. The datatable.Columns collection is a colection of DataColumns and these have a DataType property. You may be looking for System.DateTime or DateTime and it may be one of the properties of the DataType property itself :). I know it’s cumbersome but what you are asking is definitly going to be cumbersome. Once you’ve identified date columns you may be able to do something with it.

    If not i’d start looking at the data readers and see if there’s anything you can do there or with data adapters. I wish I could give you a proper answer but i think however you manage to do it, it’s not going to be pretty. Sorry

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

Sidebar

Related Questions

We have a very simple ASP.Net page for uploading a file to our webserver.
I have a very simple ASP.Net MVC Application that I have produced from an
We have a very simple ASP.NET web application comprising mostly static content and a
I'm building a very simple ASP.NET MVC site that doesn't require a database and
I have a simple ASP.NET MVC web application that uses NHibernate with FluentNHibernate's auto
I have put together a small ASP.NET MVC 2 site that does some very
I have built an asp.net page that returns an image with Response.BinaryWrite() . This
I have a very simple ASP.NET web application created under Visual Studio 2008 (SP1),
I have a simple ASP.NET page where after the initial page load the user
i have very simple problem. I need to create model, that represent element of

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.