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
>