What datasource are you binding the GridView to? Ideally, you would
bind the GridView to an IEnumerable datasource, and each item
contained within that datasource would expose certain properties.
These properties would then be accessible to the BoundFields.

For instance,

I bind a GridView to a generic List<Employee>. Each Employee object
has properties such as EmpID, Name, Designation. I can then use
BoundFields to bind to these properties.

So, in context of your question, how does the TimeString class map to
the datasource bound to your GridView? Is it exposed as a property of
that datasource?

On Apr 20, 10:12 pm, Paul <[email protected]> wrote:
> Hello All,
>
> I am trying to bind data to a GridView, but columns of type
> "TimeString" don't render if I try to do the binding programmatically.
> (Binding the data programmatically makes more sense for the page I am
> using it in). The definition of the TimeString class is pasted below
> my sig.
>
> The only way I can make the TimeString Columns render in the GridView
> is by using declarative data binding with a TemplateField as follows:
>
> <asp:TemplateField HeaderText="Direct">
>                     <ItemTemplate>
>                         <%# ((TimeString)Eval("Direct")).ToString() %>
>                     </ItemTemplate>
>                 </asp:TemplateField>
>
> If I use a BoundField with declarative binding the column renders, but
> it is the name of the class that renders. When I bind it
> programmatically the column doesn't render at all.
>
> Is there a better way to design the TimeString class so that columns
> of type TimeString render as easily as any other type, say the
> DateTime type or the string type?
>
> Thanks in advance for your help,
>
> Paul
>
> public class TimeString
>     {
>         public string HourPart { get; set; }
>         public string MinutePart { get; set; }
>
>         public TimeString(int timeSpanInMinutes)
>         {
>             int h = timeSpanInMinutes / 60;
>             int m = timeSpanInMinutes % 60;
>
>             this.HourPart = h.ToString().PadLeft(2, '0');
>             this.MinutePart = m.ToString().PadLeft(2, '0');
>         }
>
>         public string ToString()
>         {
>             return this.HourPart + ":" + this.MinutePart;
>         }
>
>         public TimeString Add(TimeString ts)
>         {
>             return new TimeString(int.Parse(this.HourPart) * 60 +
> int.Parse(ts.HourPart) * 60 + int.Parse(this.MinutePart) + int.Parse
> (ts.MinutePart));
>         }
>     }

Reply via email to