473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Data Grid Date Formating

I am Trying to Format date in my Datagrid to SHORTDATE format with the
following codes,

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

Dim dt As DateTime

dt = e.Item.Cells(2).Text

e.Item.Cells(2).Text = dt.ToString("dd-mm-yyyy")

End Sub

but I get the error Message

Cast from string "Entry Date" to type 'Date' is not valid.
Nov 18 '05 #1
1 1206
Hi Japhet:

What type of column are you using? It would probably be easier to
format the column by setting a property, for instance the BoundCoumn
has a DataFormatString property you can use to tell the grid how to
format values.

If you use ItemDataBound you have to check what type of item is
binding. From the error message it appears you might be trying to
format the column header (the string "Entry Date") as a date by first
converting the string to a date.

First check e.Item.ItemType to make sure it is a
ListItemType.AlternatingItem or a ListItemType.Item before trying to
format.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 2 Nov 2004 17:00:16 +0300, "JAPHET" <JA**********@stcl.com>
wrote:
I am Trying to Format date in my Datagrid to SHORTDATE format with the
following codes,

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs ) Handles
DataGrid1.ItemDataBound

Dim dt As DateTime

dt = e.Item.Cells(2).Text

e.Item.Cells(2).Text = dt.ToString("dd-mm-yyyy")

End Sub

but I get the error Message

Cast from string "Entry Date" to type 'Date' is not valid.


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
2
by: Les | last post by:
Hi can anyone help me, I have just graduated and have started working for a building developer which deals with a large quantity of drawings. As you can imagine these all need documenting...
1
by: Peter | last post by:
Does anyone have an example of how to format VS 2003 Data Grid that looks like the example below? I want the data to be grouped by the Date Field and display one date for each group of dates and...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
4
by: Jack M | last post by:
I have a large data grid with several rows that contain dates. I want to display the date only(no time). Even when I use the trunc function in Oracle the rows show a time of 12:00:00 am. What I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.