473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Date Won't Format

I have a GridView control that displays the data in a List<object;

My GridView contains the following in its definition:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CssClass="grid" DataSourceID="ObjectDataSource1">
<Columns>
[...]
<asp:BoundField DataField="DueDate" HeaderText="Due Date"
SortExpression="DueDate" DataFormatString="-->{0:d}<--"
HtmlEncodeFormatString="False" />
[...]
</Columns>
[...]
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetWeekDetails" TypeName="DTS.Deliveries">
[...]
</asp:ObjectDataSource>

But the DueDate column is displayed in the format "-->8/21/2008 12:00:00
AM--<". It is obviously using my format string but not to format the date.

The data is of type List<WorkDetailswhere WeekDetails is defined as:

public class WeekDetails
{
public int Week { get; set; }
public string Month { get; set; }
public DateTime DueDate { get; set; }
public int Deliveries { get; set; }
}

Deliveries.GetWeekDetails() is defined as:

public static List<WeekDetailsGetWeekDetails(int contractId, int
categoryId)
{
List<WeekDetailslist = new List<WeekDetails>();
int week = 0;

using (SqlDataReader rdr = DataHelper.ExecDataReader("SELECT DueDate,
TargetDeliveries FROM ScheduledDeliveries" +
" WHERE ContractID=@ContractID AND CategoryID=@CategoryID",
"@ContractID", contractId, "@CategoryID", categoryId))
{
int dueDateOrdinal = rdr.GetOrdinal("DueDate");
int targetOrdinal = rdr.GetOrdinal("TargetDeliveries");
while (rdr.Read())
{
week++;
WeekDetails wd = new WeekDetails();
wd.Week = week;
wd.DueDate = rdr.GetDateTime(dueDateOrdinal);
wd.Month = wd.DueDate.ToString("MMMM");
wd.Deliveries = rdr.GetInt32(targetOrdinal);
list.Add(wd);
}
}
return list;
}

I'm confident my select parameters are correct as they display the correct
results. I wondered if DueDate could've been converted to a string already
and that's why it wasn't formatting, but in the code above, I inserted a
line like string s = String.Format("{0:d}", wd.DueDate) and it appeared as
the date only as expected.

Can anyone guess what else I might try to figure out why my dates won't
format?

Thanks for any tips!

Jonathan

Aug 21 '08 #1
1 1782
Resolved:

http://weblogs.asp.net/rajbk/archive...31/429090.aspx

Jonathan

"Jonathan Wood" <jw***@softcircuits.comwrote in message
news:eK**************@TK2MSFTNGP04.phx.gbl...
>I have a GridView control that displays the data in a List<object;

My GridView contains the following in its definition:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CssClass="grid" DataSourceID="ObjectDataSource1">
<Columns>
[...]
<asp:BoundField DataField="DueDate" HeaderText="Due Date"
SortExpression="DueDate" DataFormatString="-->{0:d}<--"
HtmlEncodeFormatString="False" />
[...]
</Columns>
[...]
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetWeekDetails" TypeName="DTS.Deliveries">
[...]
</asp:ObjectDataSource>

But the DueDate column is displayed in the format "-->8/21/2008 12:00:00
AM--<". It is obviously using my format string but not to format the date.

The data is of type List<WorkDetailswhere WeekDetails is defined as:

public class WeekDetails
{
public int Week { get; set; }
public string Month { get; set; }
public DateTime DueDate { get; set; }
public int Deliveries { get; set; }
}

Deliveries.GetWeekDetails() is defined as:

public static List<WeekDetailsGetWeekDetails(int contractId, int
categoryId)
{
List<WeekDetailslist = new List<WeekDetails>();
int week = 0;

using (SqlDataReader rdr = DataHelper.ExecDataReader("SELECT DueDate,
TargetDeliveries FROM ScheduledDeliveries" +
" WHERE ContractID=@ContractID AND CategoryID=@CategoryID",
"@ContractID", contractId, "@CategoryID", categoryId))
{
int dueDateOrdinal = rdr.GetOrdinal("DueDate");
int targetOrdinal = rdr.GetOrdinal("TargetDeliveries");
while (rdr.Read())
{
week++;
WeekDetails wd = new WeekDetails();
wd.Week = week;
wd.DueDate = rdr.GetDateTime(dueDateOrdinal);
wd.Month = wd.DueDate.ToString("MMMM");
wd.Deliveries = rdr.GetInt32(targetOrdinal);
list.Add(wd);
}
}
return list;
}

I'm confident my select parameters are correct as they display the correct
results. I wondered if DueDate could've been converted to a string already
and that's why it wasn't formatting, but in the code above, I inserted a
line like string s = String.Format("{0:d}", wd.DueDate) and it appeared as
the date only as expected.

Can anyone guess what else I might try to figure out why my dates won't
format?

Thanks for any tips!

Jonathan
Aug 22 '08 #2

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

Similar topics

4
by: Gord | last post by:
Hello, VB6 accepts Date and Time values as 'Date'. I'm trying to verify entry into a database I'm creating by verifying that an appropriate Date or Time value has been entered. Using built-in...
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
2
by: Chris | last post by:
Hello, i'm using a form with 2 dates in the format mm/dd/yyyy in it. I wanna calculate the days between the two dates. I tried it like this: <script language="JavaScript"> var date1 = new...
2
by: Ian | last post by:
I would like to have some validation on a date field. The date format is dd/mm which is used for our financial year end. I suppose I need also consider leap years. Please can you shed some light on...
1
by: jim | last post by:
Hi Ng I have got a form which uses to days date - the date is stored in a table when pressing af save button. The format in the code is :Format(Me.Form.Controls("CTLDato"), "mm/dd/yy") My...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
4
by: saintor1 | last post by:
Access 97 - I want the date format YYYY-M M-DD to show everywhere. My problem is that I deal with French and English versions. And don't want to play with Windows Regional Settings. In the...
21
by: Darin | last post by:
I have an applicatoin that works 100% perfect when running on a machine setup for English (United States), but when I change it to Spanish (Mexico), the dates start giving me fits. THe reason is...
21
by: shelleybobelly | last post by:
I'm looking to return DATE ONLY for yesterday's date. No seconds, milliseconds. Formatted either yyyy/mm/dd or mm/dd/yyyy. VB does it so easily Date()-1 will return 03/27/2007 if today is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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
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
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,...

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.