Thanks so much Cerebrus - not only for taking the time to give me a detailed response, but for taking the time to edit the code to test it on your own computer.
The 'override' was the key to my problem and your reponse almost solves my problem. I am not using Visual Studio 2008. I am using Visual Web Developer Express Edition which does not give me a compiler warning for this error. It works as long as I set up the GridView like you have done, with BoundFields. What I would really like to do is have a GridView that looks like this <asp:GridView ID="grd" runat="server"/> When I try it that way, only the DateTime column renders. The reason I want to do it that way is because the page I need to use this in can have different data sources depending on what the user chooses from a DropDownList. These various data sources all have different columns, so I don't want to have the columns hardwired into the GridView. I still puzzled as to why those TimeString fields don't render automatically the way the DateTime columns do. Thanks, Paul On Apr 21, 2:24 pm, Cerebrus <[email protected]> wrote: > 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!
