Your use of Automatic properties tells me that you are using C# 3.x.
Since I do not have access to VS 2008 at the moment, I tried your
sample on .NET 2.0 and it runs without problems (after making some
necessary modifications). I elaborate on the changes I made below:
1. I changed the ToString() method signature of the TimeString class
to be an override of the inherited method from class Object. Your
compilation would have generated a warning in absence of the
"override", but I believe you missed that part. And it was the most
crucial part of the problem. This is one reason why I NEVER ignore
compiler warnings, no matter how trivial.
---
public override string ToString()
{
return this.HourPart + ":" + this.MinPart;
}
---
2. I created a constructor in the TimeSpentTimeStrings class so as to
be able to create instances of the class. I used arbitrary logic for
this. Again, this should not be relevant in your case since you appear
to be retrieving a List using the
DataAccess.AtAGlanceData.SelectTimeSpentTimeStrings() method call.
Still, for your reference, here is the constructor:
---
public TimeSpentTimeStrings(int tsInMin, DateTime thisDate)
{
direct = new TimeString(tsInMin);
indirect = new TimeString(tsInMin - 10);
travel = new TimeString(tsInMin * 10);
notes = new TimeString(tsInMin + 1);
theDate = thisDate;
}
---
3. Next I modified my Page_Load method to create 2 instances of the
TimeSpentTimeStrings class and then set the DataSource of the
GridView:
---
protected void Page_Load(object sender, EventArgs e)
{
List<TimeSpentTimeStrings> list = new List<TimeSpentTimeStrings>();
list.Add(new TimeSpentTimeStrings(37, new DateTime(2009, 3, 20)));
list.Add(new TimeSpentTimeStrings(45, new DateTime(2009, 3, 21)));
grd.DataSource = list;
grd.DataBind();
}
---
4. Lastly, I created a GridView with the following markup:
---
<asp:GridView ID="grd" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date" />
<asp:BoundField DataField="Direct" HeaderText="Direct" />
<asp:BoundField DataField="Indirect" HeaderText="Indirect" />
<asp:BoundField DataField="Travel" HeaderText="Travel" />
<asp:BoundField DataField="Notes" HeaderText="Notes" />
</Columns>
</asp:GridView>
---
And it shows up just fine. Unless I am very mistaken, the "override"
was the key.
Hope that helps!