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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:26:41+00:00 2026-05-21T05:26:41+00:00

I have a .aspx file with a datagrid in it: <asp:DataGrid ID=Gifts AutoGenerateColumns=True runat=server

  • 0

I have a .aspx file with a datagrid in it:

<asp:DataGrid ID="Gifts"
AutoGenerateColumns="True"
runat="server" AllowSorting="True">
    </asp:DataGrid>

The .aspx.vb file associated with it fills it in with a datagrid object.

Protected WithEvents Gifts As System.Web.UI.WebControls.DataGrid
Public GiftData As DataTable
Gifts.DataSource = New DataView(GiftData)
Gifts.DataBind()

That all works fine. However I want to format one of the columns with a particular date format. Is there a way of doing that in the vb code? I know I can do it in the .aspx by specifing AutoGenerateColumns=”False” and then explicitly defining the columns, but I want to do it in the code as it’s more future proof for my application.

  • 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-21T05:26:42+00:00Added an answer on May 21, 2026 at 5:26 am

    You could do this in RowDataBound-Eventhandler:

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
         If e.Row.RowType = DataControlRowType.DataRow Then
            'If the first column is a date
            e.Row.Cells(0).Text = String.Format("{0:D}", Date.Parse(e.Row.Cells(0).Text))
         End If
    End Sub
    

    If you’re really using an old DataGrid, it works nearly the same. Use DataGrid’s
    ItemDataBound-Event instead.

    Protected Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
         If e.Item.ItemType = ListItemType.Item orelse e.Item.ItemType = ListItemType.AlternatingItem Then
            'If the first column is a date
            e.Item.Cells(0).Text = String.Format("{0:D}", Date.Parse(e.Item.Cells(0).Text))
         End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created this datagrid in my .aspx file. <asp:datagrid id=Computerchange runat=server AllowPaging=True PageSize=2 AutoGenerateColumns=False
I have an ASPX file with this button: <asp:button id=cmdPartnerInfo runat=server Font-Bold=True Text=Partner Info
I have a ListView in my aspx file like this: <asp:ListView ID=ListView1 runat=server></asp:ListView> and
in aspx file I have <asp:DropDownList ID=DropDownList1 runat=server > </asp:DropDownList> <asp:DropDownList ID=DropDownList2 runat=server> </asp:DropDownList>
I have the following code in my .aspx file <asp:Table ID=tabStudent runat=server></asp:Table> I declared
I have a following aspx:dropdown in aspx file: <asp:DropDownList ID=ddlbStatus Width=210px Height=30px CssClass=ddlb runat=server
i have this code in my default aspx file : <body> <form id=form1 runat=server>
I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I have the following markup in a DataGrid: <itemtemplate> <a href='~/File.aspx?item=<%# DataBinder.Eval(Container.DataItem, ItemID).ToString() %>'
I have MyPage.aspx file and a button within. The button has server click event:

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.