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

Home Posts Topics Members FAQ

gridview, databinding, date and formatting problem

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>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn

Nov 23 '06 #1
12 5948

ta******@gmail. com schreef:
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>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn
It seems that when you "change this row to a templatefield" the
dataformat property is not available anymore. Not entirely unlogical
but can I format the strings of the row for let's say theItemTemplate ?
Any help is greatly appreciated.

Nov 23 '06 #2
You can format your date in your query to return the date in the format you
want.

If using SQL Server: CONVERT(DATETIM E, YourField, 1)

In my opinion, it is much easier to just return the data as you want it then
to send back something you don't need, in the case of a time on the date, and
then format it.

"ta******@gmail .com" wrote:
>
ta******@gmail. com schreef:
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>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn

It seems that when you "change this row to a templatefield" the
dataformat property is not available anymore. Not entirely unlogical
but can I format the strings of the row for let's say theItemTemplate ?
Any help is greatly appreciated.

Nov 23 '06 #3
"Mike Collins" <Mi*********@di scussions.micro soft.comwrote in message
news:89******** *************** ***********@mic rosoft.com...
You can format your date in your query to return the date in the format
you
want.

If using SQL Server: CONVERT(DATETIM E, YourField, 1)

In my opinion, it is much easier to just return the data as you want it
then
to send back something you don't need, in the case of a time on the date,
and
then format it.
I disagree totally.

For one thing, the CONVERT function in SQL Server has a fairly limited
number of options for dates - certainly nothing like the richness that is
available with the .ToString() method in .NET.

Secondly, it really isn't the job of the database layer to provide
formatting - that's for the presentation layer. Much better, IMO, to let SQL
Server return the native data to to the GUI (through the business layer(s),
as required) and let the GUI control how that data is displayed...
Nov 23 '06 #4

Mark Rae schreef:
"Mike Collins" <Mi*********@di scussions.micro soft.comwrote in message
news:89******** *************** ***********@mic rosoft.com...
You can format your date in your query to return the date in the format
you
want.

If using SQL Server: CONVERT(DATETIM E, YourField, 1)

In my opinion, it is much easier to just return the data as you want it
then
to send back something you don't need, in the case of a time on the date,
and
then format it.

I disagree totally.

For one thing, the CONVERT function in SQL Server has a fairly limited
number of options for dates - certainly nothing like the richness that is
available with the .ToString() method in .NET.

Secondly, it really isn't the job of the database layer to provide
formatting - that's for the presentation layer. Much better, IMO, to let SQL
Server return the native data to to the GUI (through the business layer(s),
as required) and let the GUI control how that data is displayed...
Thanks all for the replies.

Since I actually need it for more than date formatting, SQGformatting
is not really an option. I 'm really interested on how I can do this in
asp.net itself. Someone can help me here?

thanks in advance

Nov 23 '06 #5
For a normal bounded field it's easy;
1) Turn off html encoding
2) Do the formatting stuff on the specific format property like
{0:yyyy-MM-dd}

<ta******@gmail .comschreef in bericht
news:11******** **************@ j44g2000cwa.goo glegroups.com.. .
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>

Can I add some code that only the date will be shown and not the time?

Best regards,
Stijn

Nov 23 '06 #6
<ta******@gmail .comwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
Since I actually need it for more than date formatting, SQGformatting
is not really an option. I 'm really interested on how I can do this in
asp.net itself. Someone can help me here?
pseudo-code:

DataSet objDS = new <populate a DataSet>;
DateTime dtmDate = objDS.GetDateTi me(0);
string strDateAsText = String.Empty;
strDateAsText = dtmDate.ToStrin g("dd MMM yyyy");
strDateAsText = dtmDate.ToStrin g("dd MMM yyyy HH:mm");
strDateAsText = dtmDate.ToStrin g("yyyyMMddHHmm ss");

http://www.microsoft.com/globaldev/g.../wrg_date.mspx
Nov 23 '06 #7
I agree with Mike...

Plus, if you only return the data that you need, you save bandwidth. I know,
it may not be that much, but it adds up. IMO it is the same as not typing
Select * From Table, when Select MyOneField From Table is much better because
you are sending less data over the network.

I just recently used things like this because a page was taking too long to
finish downloading to a client's computer. It was not because the page was
broken. It was because of all the data that the page was displaying. By
making squeezing out every possible ounce of fat I could from the page, it
now loads over twice as fast.

So, if you do not need the information, why send it to only have to strip it
off anyway?

"Mark Rae" wrote:
"Mike Collins" <Mi*********@di scussions.micro soft.comwrote in message
news:89******** *************** ***********@mic rosoft.com...
You can format your date in your query to return the date in the format
you
want.

If using SQL Server: CONVERT(DATETIM E, YourField, 1)

In my opinion, it is much easier to just return the data as you want it
then
to send back something you don't need, in the case of a time on the date,
and
then format it.

I disagree totally.

For one thing, the CONVERT function in SQL Server has a fairly limited
number of options for dates - certainly nothing like the richness that is
available with the .ToString() method in .NET.

Secondly, it really isn't the job of the database layer to provide
formatting - that's for the presentation layer. Much better, IMO, to let SQL
Server return the native data to to the GUI (through the business layer(s),
as required) and let the GUI control how that data is displayed...
Nov 23 '06 #8
"Wannabe" <Wa*****@discus sions.microsoft .comwrote in message
news:2F******** *************** ***********@mic rosoft.com...
Plus, if you only return the data that you need, you save bandwidth.
Oh for heaven's sake. A smalldatetime field in SQL Server is 4 bytes big
(look it up). Convert it to a varchar so that it returns "01 Nov 2006" - now
it's 11 bytes...
I know, it may not be that much, but it adds up. IMO it is the same as not
typing
Select * From Table, when Select MyOneField From Table is much better
because
you are sending less data over the network.
I fully agree - but what does that have to do with formatting dates...?
Nov 23 '06 #9
I fully agree - but what does that have to do with formatting dates...?

You do make a good point...let SQL Server do what it does best, get data.
Enough so, that I will be doing some reading on the subject, to see what the
best practice is. I was just trying to point out that you should be aware of
the amount of data that is being sent over the network, as a whole. So it was
just the concept I am trying to point out.

"Mark Rae" wrote:
"Wannabe" <Wa*****@discus sions.microsoft .comwrote in message
news:2F******** *************** ***********@mic rosoft.com...
Plus, if you only return the data that you need, you save bandwidth.

Oh for heaven's sake. A smalldatetime field in SQL Server is 4 bytes big
(look it up). Convert it to a varchar so that it returns "01 Nov 2006" - now
it's 11 bytes...
I know, it may not be that much, but it adds up. IMO it is the same as not
typing
Select * From Table, when Select MyOneField From Table is much better
because
you are sending less data over the network.

I fully agree - but what does that have to do with formatting dates...?
Nov 23 '06 #10

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

Similar topics

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
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....
3
13757
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
4
13497
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. I just set the GridView.DataSource once, and call DataBind(); I'd like to drive the application from the GridView control, by including command buttons that allow editing of the data. Starting out simple, I have a DataTable with a boolean...
5
1637
by: Edwin Knoppert | last post by:
I want to format a hyperlink bounded field. Fields *could* have http:// *or not* in the websitename entered. I want to format this to http://website.com otherwise i'll get a relative link. I know the itemtemplate workarounds or through row events. It's that i'm trying to use the internal format stuff itself. Is this possible?
3
2099
by: Simon Harvey | last post by:
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:TemplateField HeaderText="Departure Date"> <ItemTemplate>
9
11839
by: J055 | last post by:
Hi I'm trying to get an instance of UserLists to persist after it's been used by the GridView. I understand from the documentation that The OnObjectCreated event allows access to the instance. I have a TotalUsers property which is initiated when the GetUsers method is called, however it is empty after the OnObjectCreated event runs. What am I doing wrong? Is there a way to get the Row count from the GetUsers method (It is a DataTable)?...
1
3252
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
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...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
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...
1
10323
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,...
1
7621
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
5525
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...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
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.