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