473,587 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataFormatStrin g not working on a GridView DateTime column

I have a GridView that is bound to a collection of DateTimes (i.e. -
Collection<Date Time>). I have a BoundField in the GridView, and its
DataField is set to the DateTime's Date property, and the DataFormatStrin g
is set to "{0:d}" in order to display the date in short date format (without
the time). But the DataFormatStrin g doesn't seem to have any effect. The
DateTime gets displayed with the time.

I have another GridView that is bound to a collection of business objects,
and the business objects have a DateTime property. One of the columns in
the GridView has a BoundField that uses this DateTime property as its
DataField. In this case, the "{0:d}" DataFormatStrin g works as it should.
(The DateTime is displayed in short date format, without the time.) So it
works in this case, but not when I have the GridView bound to a collection
of DateTimes.

I've worked around the problem by using the RowDataBound event to manually
trim the time from the end of the cell's text, but that's a kludgy
workaround. Does anyone know why the DataFormatStrin g isn't working
correctly in this case?

Thanks in advance,
--Rob Roberts
Apr 9 '06 #1
2 16344
Hi,

set HtmlEncode="Fal se" to the BoundField.

Reason is that by default data is HTML-encoded before string formatting
takes place (which actually prevents string formatting to apply at all)
For an explanation see:
http://aspadvice.com/blogs/joteke/ar.../25/12871.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Rob Roberts" <ro************ @AndThisToo.pci sys.net> wrote in message
news:uV******** ********@TK2MSF TNGP04.phx.gbl. ..
I have a GridView that is bound to a collection of DateTimes (i.e. -
Collection<Dat eTime>). I have a BoundField in the GridView, and its
DataField is set to the DateTime's Date property, and the DataFormatStrin g
is set to "{0:d}" in order to display the date in short date format
(without the time). But the DataFormatStrin g doesn't seem to have any
effect. The DateTime gets displayed with the time.

I have another GridView that is bound to a collection of business objects,
and the business objects have a DateTime property. One of the columns in
the GridView has a BoundField that uses this DateTime property as its
DataField. In this case, the "{0:d}" DataFormatStrin g works as it should.
(The DateTime is displayed in short date format, without the time.) So it
works in this case, but not when I have the GridView bound to a collection
of DateTimes.

I've worked around the problem by using the RowDataBound event to manually
trim the time from the end of the cell's text, but that's a kludgy
workaround. Does anyone know why the DataFormatStrin g isn't working
correctly in this case?

Thanks in advance,
--Rob Roberts

Apr 9 '06 #2
"Teemu Keiski" <jo****@aspalli ance.com> wrote in message
news:OH******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

set HtmlEncode="Fal se" to the BoundField.


Yes, that fixed it. Thank you!

--Rob Roberts
Apr 9 '06 #3

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

Similar topics

1
2988
by: scj | last post by:
Hi all, I need to determine the exact type of DateTime column(*) in an Access 97 database. I'm able to do this with an Access 2 database. With ADO.Net and VB.Net (**), I do something like this : Dim oDT As New DataTable() Dim oCnx As OleDbConnection
1
2202
by: | last post by:
I'm wondering if it's possible, outside of the declaration of an ASP.NET 2.0 GridView, to programmatically style individual columns. For example, I might want to make the text in a particular column bold, or larger. I know that Templates and other declarative mechanisms exist to make this happen. I'm wondering if you can apply the styling using code only. What is the general syntax? Flash Actionscript has this "after the fact"...
1
6615
by: Hardy Wang | last post by:
Hi, I have a GridView control in my web form (ASP.NET 2.0) <asp:GridView ID="gvReport" runat="server" AllowSorting="True" AutoGenerateColumns="False" Width="100%"> <HeaderStyle CssClass="ItemCaption" /> <RowStyle CssClass="Line" /> <AlternatingRowStyle CssClass="AltLine" /> <Columns> <asp:BoundField DataField="ItemName" HeaderText="Item
2
2136
by: Anonieko | last post by:
Hello ASPNET guru's, What is a clean way to go around the problem of displaying a GridView templated column where data can contain Single Quote ( ' )? I maybe too naive, but this is of course a common scenario. Scenario: * My database returns names that can contain single quote.
5
51591
by: GG | last post by:
I am trying to add a nullable datetime column to a datatable fails. I am getting exception DataSet does not support System.Nullable<>. None of these works dtSearchFromData.Columns.Add( new DataColumn( "StartDate", typeof( DateTime? ) ) ); dtSearchFromData.Columns.Add( new DataColumn( "EndDate", typeof( System.Nullable<DateTime>) ) ); Any ideas?
1
3665
by: Neven Klofutar | last post by:
Hi, I have a questin regarding GridView, Template column and Checkbox in it. I'm working on a project that has several "client" applications entering data into DB, and one "admin" application reviewing that data. Since data that admin app can see "must be refreshed in real time", I've created Anthem GridView and AnthemTimer fireing every 5s and rebindind data to GridView every time. GridView has several Bound columnes and 1 template...
4
9448
by: TS | last post by:
I have a headerText for a header column that is "Page<br>Name". it puts a <brto force a line break, but the < and get encoded to &lt; and &gt; thus negating its effect as an html control and doesn't respect the line break I'm guessing this happens during render. What do i need to do to keep the line break?
2
2413
by: yahshuatwo | last post by:
How can you display an icon the gridview cell column which is dependent on the text value of an adjacent column. Also, I setup the asp template,item and image controls, do i need to set the imgURL value in the asp control side? here's my code below: protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ...
0
1851
by: premtolani | last post by:
Hello, Can you tell me how to sort a datetime column in any datetime format in a swt table ? the datetime format can be any. regards, Prem
0
8219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.