473,804 Members | 3,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting my date in the GridView :-(

Hi all,

I'm having problems getting my date to format. Someone told me that with
the GridView, you need to use a TemplateColumn and not a BoundColumn when
displaying dates.

Given that, can anyone see what the problem is with the following code....

<asp:TemplateFi eld HeaderText="Dep arture Date">
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DepartDat e",
"{0:dd-mm-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

When it comes to rendering, the grid continues to display the full date and
time. It's as though it's just ignoring the date formatting instruction.

Can anyone tell me why.

I'd be very grateful if anyone could help

Thanks

Simon
Feb 14 '06 #1
3 2098
You dont need template columns to format a bound date column.

<asp:BoundColum n DataField="Firs tPublished" HeaderText="Pub lished"
DataFormatStrin g="{0:dd/MM/yyyy}">
</asp:BoundColumn >

HTH

Terry Burns
http://TrainingOn.net
"Simon Harvey" <no******@hotma il.com> wrote in message
news:7c******** *************** ***@news.micros oft.com...
Hi all,

I'm having problems getting my date to format. Someone told me that with
the GridView, you need to use a TemplateColumn and not a BoundColumn when
displaying dates.

Given that, can anyone see what the problem is with the following code....

<asp:TemplateFi eld HeaderText="Dep arture Date">
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("DepartDat e", "{0:dd-mm-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

When it comes to rendering, the grid continues to display the full date
and time. It's as though it's just ignoring the date formatting
instruction.

Can anyone tell me why.

I'd be very grateful if anyone could help

Thanks

Simon

Feb 14 '06 #2
If using GridView in ASP.NET 2.0 and BoundField, you might run into string
formatting issue where you also need to set HtmlEncode="Fal se" for the
BoundField.for it to take effect.

http://aspadvice.com/blogs/joteke/ar.../25/12871.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Terry Burns" <me@mine.com> wrote in message
news:ux******** ******@TK2MSFTN GP09.phx.gbl...
You dont need template columns to format a bound date column.

<asp:BoundColum n DataField="Firs tPublished" HeaderText="Pub lished"
DataFormatStrin g="{0:dd/MM/yyyy}">
</asp:BoundColumn >

HTH

Terry Burns
http://TrainingOn.net
"Simon Harvey" <no******@hotma il.com> wrote in message
news:7c******** *************** ***@news.micros oft.com...
Hi all,

I'm having problems getting my date to format. Someone told me that with
the GridView, you need to use a TemplateColumn and not a BoundColumn when
displaying dates.

Given that, can anyone see what the problem is with the following
code....

<asp:TemplateFi eld HeaderText="Dep arture Date">
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%#
Bind("DepartDat e", "{0:dd-mm-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

When it comes to rendering, the grid continues to display the full date
and time. It's as though it's just ignoring the date formatting
instruction.

Can anyone tell me why.

I'd be very grateful if anyone could help

Thanks

Simon


Feb 14 '06 #3
Hi Guys

I am using the GridView control and I've tried doing the html encoding thing
as well. I'm a bit stuck now because I can't get either version to work.

I must be doing something stupid or my setup is different to everyone elses
or something. Not sure what it is though :-(

Thanks for your help though

Simon
Feb 15 '06 #4

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

Similar topics

0
1091
by: John Smith | last post by:
Hello, I am a longtime ASP Classic guy, and I am new to .NET. I am hoping someone can help me with what is probably a simple question. I have a stored procedure that returns 5 rows from a database. I would like to display the results as such: DATE Text
3
6224
by: washoetech | last post by:
I have a gridview control. In this grid view there is a column for the price of an item. Some of the prices have a dollar sign in front of it and some dont. How do I get rid of the dollar sign if it is in front of the value? My guess would be to use a template column but I dont know how to go about this. Any ideas? Below is an example of what the data looks like raw from the database: $456.95 200.89
5
1563
by: Shimon Sim | last post by:
I just don't understand what is wrong. I have simple query. One of the returning fields is data I created bound column for GridView (ASP.NET 2.0) and specified DataFormatString as {0:d} - it returns me the row date with hours. I tried something like this {0 :dd/MM/yyyy} the same results. It looks like that system doesn't recognize that the field is date. Why not? What can be done? Thank you,
4
2621
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I re-format the updated row fields. I have looked at gridView.rowUpdated method, but cannot figure out how....
2
2273
by: David Veeneman | last post by:
How does one format a date column in a GridView control? I had assumed that the DataFormat string would do it, but MSDN only shows numeric formatting codes. Can dates be formatted using that property, or is it done some other way? Thanks in advance. -- David Veeneman Foresight Systems
2
2703
by: J055 | last post by:
Hi I've been looking into different ways of formatting columns/rows in the GridView control. I realize now, I think, that once the datasource is bound to the control the original column type information is lost, i.e. converted to a string. So my question is: is it better to format data while it's still in a DataTable, for example, then bind it to the control, or format the strings in the BoundField elements, or if more flexibility is...
3
2403
by: CSharpguy | last post by:
I'm trying to format the GridView on my web form and its not working. for money I have {0:C} and for date fields, I have {0:d} and the format isn't changing, what else do I need to do to get the formatting working in the gridView?
4
8338
by: Ken Wigle | last post by:
All, I would be very grateful for any help on this question. I have an application in asp.net 2.0 where I dynamically create a datatable and then bind that to a gridview. Unfortunately, the date column always shows the date and time while I just want the short date. I have tried applying a format string {0:d} but to no avail. I saw a lot of posts regarding the htmlencode property but I do not know how to turn that off for a...
12
5948
by: tarscher | last post by:
Hi all, A simple problem that seems hard to solve... I have a gridview with a date row. <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("time") %>'></asp:Label> </ItemTemplate>
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10320
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
10077
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
9150
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...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
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
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
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
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.