I have a GridView that is bound to a collection of DateTimes (i.e. -
Collection<DateTime>). I have a BoundField in the GridView, and its
DataField is set to the DateTime's Date property, and the DataFormatString
is set to "{0:d}" in order to display the date in short date format (without
the time). But the DataFormatString 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}" DataFormatString 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 DataFormatString isn't working
correctly in this case?
Thanks in advance,
--Rob Roberts 2 16325
Hi,
set HtmlEncode="False" 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.pcisys.net> wrote in message
news:uV****************@TK2MSFTNGP04.phx.gbl... I have a GridView that is bound to a collection of DateTimes (i.e. - Collection<DateTime>). I have a BoundField in the GridView, and its DataField is set to the DateTime's Date property, and the DataFormatString is set to "{0:d}" in order to display the date in short date format (without the time). But the DataFormatString 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}" DataFormatString 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 DataFormatString isn't working correctly in this case?
Thanks in advance, --Rob Roberts
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl... Hi,
set HtmlEncode="False" to the BoundField.
Yes, that fixed it. Thank you!
--Rob Roberts This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 < and >
thus negating its effect as an html control and doesn't...
|
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...
|
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
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
| |