473,513 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Displaying only Datepart in Datagrid

390 Recognized Expert Contributor
Hi,

I have one requirement to display only the Date part of a DateTime column in datagrid.
My DateTime column may contain null values also.
My concern is while inserting the value into the table ,I am using it as
DateTime.Now.Date but it stores the values as "29/08/2007 00:00:00".
I only want 29/08/2007 in my datagrid.
How to do that?If I can insert 29/08/2007 only ,it will also help me.
Please suggest
Aug 29 '07 #1
2 1292
nateraaaa
663 Recognized Expert Contributor
Hi,

I have one requirement to display only the Date part of a DateTime column in datagrid.
My DateTime column may contain null values also.
My concern is while inserting the value into the table ,I am using it as
DateTime.Now.Date but it stores the values as "29/08/2007 00:00:00".
I only want 29/08/2007 in my datagrid.
How to do that?If I can insert 29/08/2007 only ,it will also help me.
Please suggest
You have a few options.
1. You can insert only the date into the database by using DateTime.Now.ToShortDateString().
2. You can insert the date as you are and use String.Format to control how the date will be displayed in your datagrid. You will need to add an TemplateColumn and ItemTemplate in your datagrid. Use a label control in your ItemTemplate to hold the date.
Example.
string date = "29/08/2007"; //replace this with the row/column value returned to your dataset.
Label1.Text = String.Format("{0:dd/MM/yyyy}", date);

Either way should work for you.

Nathan
Aug 29 '07 #2
mzmishra
390 Recognized Expert Contributor
Thanks for the guideline.

It works fine now for me..
Aug 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6283
by: David | last post by:
Hi Group, i am trying to use the DatePart function on my SQL2000 database. I have a table called visitors with a field called DateTimeEntrance which is filled everytime a visitor enters the site....
1
5075
by: J. Muenchbourg | last post by:
Looking thru my resources, I cannot find a simple way of displaying next sunday's date depending on what todays date is. I'd like to do it without doing 7 if statements or case select: ...
1
1245
by: Maziar Aflatoun | last post by:
Hi everyone, I have this DataGrid that I bind to a DataTable. However, instead of displaying the column 'Qty', I like to place it in a textbox and display the value of Qty as the default value...
3
4891
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
4
2195
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
3
9857
by: S. van Beek | last post by:
Dear reader, With DatePart() you can subtract the year or the week from a date field with: DatePart("yyyy";) for the year
2
2112
by: le0 | last post by:
Hello guys, Is there anything wrong with my code (see below) bcoz when 10p-6a shift my browser returns the error cannot be a zero-length string. Im wondering why, bcoz the 2 other shift works...
1
1380
by: sushant2009 | last post by:
Hi , I want to display empty databae table(actually table contains lot of records) to datagrid using dataset and dataadpter. After displaying i will fill new records in datagrid and i will save...
3
3583
by: grabit | last post by:
Hi Peoples I am having probs with the datepart function with a query.What i want is to get all listings made in any month in any year ie May 2007 i have 2 drop down boxes to select the listedmonth...
0
7166
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
7386
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
7543
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
7534
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...
1
5094
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...
0
4749
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...
0
3236
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...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
805
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.