Formatting fields in VS.NET 2.0 GridView control

Posts   
 
    
davea
User
Posts: 5
Joined: 12-Jan-2006
# Posted on: 12-Jan-2006 17:08:40   

I am trying to format the date fields coming from the database in MM/DD/YYYY format but adding the dateformatstring to the boundcolumn does not seem to be working.

The code for the column is

                 <asp:BoundField DataField="Created" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Created" SortExpression="Created" />

and I am binding to a typedlist in code as follows

     protected void BindData(ISortExpression sorter, IPredicateExpression filter)
    {
        eFinancials.TypedListClasses.InvoiceGridTypedList invoices = new eFinancials.TypedListClasses.InvoiceGridTypedList();
        invoices.Fill(0, sorter, false, filter);
        this.GridView1.DataSource = invoices;
        this.GridView1.DataBind();
    }

Any ideas why the formatting is not working? Does it have to do with the design-time issues with the gridview with the current version of LLBLGEN?

Thanks, Dave

davea
User
Posts: 5
Joined: 12-Jan-2006
# Posted on: 12-Jan-2006 20:35:44   

am trying to format the date fields coming from the database in MM/DD/YYYY format but adding the dateformatstring to the boundcolumn does not seem to be working.

The code for the column is

 <asp:BoundField DataField="Created" DataFormatString="{0:MM/dd/yyyy}" HeaderText="Created" SortExpression="Created" />

and I am binding to a typedlist in code as follows


protected void BindData(ISortExpression sorter, IPredicateExpression filter)
{
eFinancials.TypedListClasses.InvoiceGridTypedList invoices = new eFinancials.TypedListClasses.InvoiceGridTypedList();
invoices.Fill(0, sorter, false, filter);
this.GridView1.DataSource = invoices;
this.GridView1.DataBind();
} 

Any ideas why the formatting is not working? Does it have to do with the design-time issues with the gridview with the current version of LLBLGEN?

Thanks, Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 12-Jan-2006 21:02:32   

What exactly does 'doesn't work' mean? You get an exception or the formatting is ignored or something else?

Frans Bouma | Lead developer LLBLGen Pro
davea
User
Posts: 5
Joined: 12-Jan-2006
# Posted on: 12-Jan-2006 21:04:09   

The formatting is ignored. It comes out like 09/21/2005 7:17:40 AM with the time added on in the grid instead of 09/21/2005.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jan-2006 06:50:23   
davea
User
Posts: 5
Joined: 12-Jan-2006
# Posted on: 13-Jan-2006 14:56:44   

Thanks, that was the problem!

briansp avatar
briansp
User
Posts: 17
Joined: 30-Sep-2005
# Posted on: 10-Feb-2006 23:46:08   

Yeah, this helped me too. I thought maybe there was something wrong with my EntityCollection. Thanks!