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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:57:21+00:00 2026-05-21T16:57:21+00:00

In an aspx page I am binding the labels like this: <asp:TemplateField HeaderText=Date of

  • 0

In an aspx page I am binding the labels like this:

  <asp:TemplateField HeaderText="Date of Joining">
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%# Eval("date_of_joining") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Paid Priviledge Date">
            <ItemTemplate>
                <asp:Label ID="Label8" runat="server" 
                    Text='<%# Eval("paid_priviledge_date") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>

And in the code behind I’m binding the grid view like this :(minimum code is given)

GridView1.DataSource = dt2;
GridView1.DataBind();

But the gridview columns show the date like this :

4/12/2011 12:00:00 AM    
4/4/2011 12:00:00 AM

Please suggest how to remove the time stamp part and to display only the date part.

I know how to do this by formatting using ToString and SubString. But I am not able to do this in gridview.

  • 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. Editorial Team
    Editorial Team
    2026-05-21T16:57:22+00:00Added an answer on May 21, 2026 at 4:57 pm

    Create a FormatDate method in your codebehind, and call that from your gridview.
    http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
    http://www.csharp-examples.net/string-format-datetime/

    This part will go in your code behind

    private object FormatDate(DateTime input)
    {
        return String.Format("{0:MM/dd/yy}", input);
    }
    

    And this bit will go in your markup

        <asp:TemplateField HeaderText="Date of Joining">
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%# FormatDate(Eval("date_of_joining")) %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Paid Priviledge Date">
            <ItemTemplate>
                <asp:Label ID="Label8" runat="server" 
                    Text='<%# FormatDate(Eval("paid_priviledge_date")) %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    

    This is what I would call a D.R.Y. approach to the problem. If you ever need to modify the formatting in any way. You can simply edit the code behind method and it will rain down sweet love to all of your markup.

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

Sidebar

Related Questions

in the aspx page i am getting this error while binding dropdown list Unable
I have an ASPX page and on this page I have a control that
I am using a master page... Then there is an .aspx that uses this
Is there any difference between performing binding on .aspx page via <%# some code
I am using an asp:Repeater control in my .aspx page that looks similar to:
I am using an asp:Repeater control in my .aspx page that looks similar to:
Followed this example on telerik's website and implemented as follows:- aspx page:- <div id=div1
In SharePoint I can tee up a binding to an edit field like this
I have a asp.net page I'm writing and I'm perplexed by this problem. I
Within an ASPX page, I would like to have the popup shown within the

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.