PC Review


Reply
Thread Tools Rate Thread

Date Won't Format

 
 
Jonathan Wood
Guest
Posts: n/a
 
      21st Aug 2008
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<WorkDetails> where 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<WeekDetails> GetWeekDetails(int contractId, int
categoryId)
{
List<WeekDetails> list = 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

 
Reply With Quote
 
 
 
 
Jonathan Wood
Guest
Posts: n/a
 
      22nd Aug 2008
Resolved:

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

Jonathan

"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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<WorkDetails> where 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<WeekDetails> GetWeekDetails(int contractId, int
> categoryId)
> {
> List<WeekDetails> list = 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
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting complex date format to normal date format in Excel BlackNarcissus Microsoft Excel Misc 0 28th Jul 2011 04:28 PM
permanent conversion of 1904 date format to 1900 date format Jos Microsoft Excel Worksheet Functions 3 21st Jul 2009 06:32 PM
converting general date format data into short date format savigliano Microsoft Access Form Coding 3 27th Nov 2006 04:37 AM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier Microsoft Excel Programming 0 22nd Sep 2004 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Microsoft Excel Programming 1 24th Nov 2003 11:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:49 AM.