Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:55:18+00:00 2026-06-18T03:55:18+00:00

I have an asp.net gridview bound to the following sql server 2008r2 data source:

  • 0

I have an asp.net gridview bound to the following sql server 2008r2 data source:

<asp:SqlDataSource ID="dsFault" runat="server" DataSourceMode="DataSet" 
 ConnectionString="<%$ ConnectionStrings:ESBExceptionDb %>"
SelectCommand="select * from Fault order by datetime desc"></asp:SqlDataSource>

In my Fault table there is a column called DateTime of type datetime. The values stored in this column are in UTC format and I need them to be displayed in the local timezone for the browser

I have added a template field to the Columns collection of the grid view as follows:

<asp:TemplateField>
  <ItemTemplate>
   <asp:Label ID="lblLocalTime" runat="server" 
    Text='<%# String.Format("{0:f}", Eval("DateTime").ToLocalTime()) %>'>
   </asp:Label>
  </ItemTemplate>    
</asp:TemplateField>

When I browse the page I get the following error:

CS1061: 'object' does not contain a definition for 'ToLocalTime' and no
extension method 'ToLocalTime' accepting a first argument of type 'object' 
could be found (are you missing a using directive or an assembly reference?)

Can anyone please tell me where I’ve gone wrong?

Thanks, Rob.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:55:20+00:00Added an answer on June 18, 2026 at 3:55 am

    The Eval("DateTime") Value that returns from your database is not a C# DataTime object.

    and because the function .ToLocalTime() belongs to the DateTime c# object you can’t use it.

    You need to convert the object to string and then use the function .ToLocalTime()

    <asp:TemplateField>
      <ItemTemplate>
       <asp:Label ID="lblLocalTime" runat="server" 
        Text='<%# Convert.ToDateTime(Eval("DateTime")).ToLocalTime() %>'>
       </asp:Label>
      </ItemTemplate>    
    </asp:TemplateField>
    

    Ones you converted it to DateTime Object, you can use any format available

    For Example

    Text='<%# Convert.ToDateTime(Eval("DateTime")).ToString("dd/MM/yyyy") %>'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET control that I have bound to a SQL result: <asp:GridView
I have added a GridView control on my ASP.net webpage and data bound it
I have gridview in my asp.net page which is bound to sqldatasource. when i
I have an ASP.net GridView that spits out three columns of data: ( OrderNumber,
I have an ASP.NET GridView that's bound to an ObjectDataSource (which is bound to
I have a fairly big asp.net website that use GridView bound to the same
I have a GridView on ASP.NET web form which I have bound to a
I am looking for rowdata bound event that we have in asp.net gridview. What
Using VWD 2010 Express, ASP.NET, VB.NET. I have a gridview that is bound to
I have an ASP.NET gridview component which is being filled up with data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.