473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DateTime Problem in GridView/DataList

Hi,

I am using an MS SQL Database with a table that has a DateTime column stored in it.

When I try to bind the data inside this table to a GridView and/or DataList the date shows up as (for example) '2010-03-03T00:00:00+01:00'.

In my GridView I tried to format that datetime by using the following 'BoundField' tag;

<asp:BoundField DataField="NewsDateEntered" HeaderText="Date Entered" DataFormatString = "{0:dd/MM/yyyy}" HtmlEncode="False" />

This is still wielding no results and I have tried to recreate the table and so on. Does anyone have any idea what my problem could be please?

Thanks
Mar 17 '10 #1
2 2193
CroCrew
564 Expert 512MB
Can you show the code that you are using to bind the data so we can help. Also, in the database how is that being stored? String, dataTime, or other?

CroCrew~
Mar 24 '10 #2
CroCrew
564 Expert 512MB
Without seeing your code it is hard to help. Here is an example that might help you out a bit.

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default10.aspx.vb" Inherits="Default10" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.     <head runat="server">
  5.         <title></title>
  6.     </head>
  7.     <body>
  8.         <form id="form1" runat="server">
  9.             <div>
  10.                 <asp:DataGrid ID="Grid" runat="server" AutoGenerateColumns="False" GridLines="None">
  11.                     <Columns>
  12.                         <asp:BoundColumn DataField="NewsDateEntered" HeaderText="Date Entered" DataFormatString="{0:dd/MM/yyyy}" />
  13.                     </Columns>
  14.                 </asp:DataGrid>            
  15.             </div>
  16.         </form>
  17.     </body>
  18. </html>
  19.  
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2.  
  3. Partial Class Default10
  4.     Inherits System.Web.UI.Page
  5.  
  6.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.         Dim mydatatable As New DataTable
  8.         mydatatable.Columns.Add("NewsDateEntered", Type.GetType("System.String"))
  9.         Dim myrow As DataRow
  10.  
  11.         myrow = mydatatable.NewRow
  12.         myrow("NewsDateEntered") = DateTime.Parse("2010-03-03T00:00:00+01:00")
  13.         mydatatable.Rows.Add(myrow)
  14.  
  15.         Grid.DataSource = mydatatable
  16.         Grid.DataBind()
  17.     End Sub
  18. End Class
  19.  
We could help out more if we could see all your code.

Happy Coding,
CroCrew~
Mar 24 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in...
3
by: Martin | last post by:
Hi, I have a very frustrating problem that I have researched for countless hours to no avail. There are many posts asking very similar things, however none usefull in my situation. I am using VS...
1
by: staeri | last post by:
I want to count the rows in a GridView which is nested into a DataList but I can't find the correct syntax for this. Can someone please help me with this and also tell me how to reference a text...
4
by: Bishop | last post by:
I want to find out if there is a way to use the gridview to list products simular to the listing on this page:...
0
by: H5N1 | last post by:
Hi there My problem is that in when I update GridView row, which is nested into DataList control, I want to refresh also DataList in which the GridView is nested, since after update, trigger in...
1
by: H5N1 | last post by:
Hello everybody I'm stuck for a long time with the following problem, so I will be really gratefull if you could help me a bit: I have a GridView nested in DataList (it's located in DataList's...
0
by: ammar_fake | last post by:
Hello there. I need a DataList to render the Gridview by providing one of the DataList values as a query for the underlaying Gridview. This does not work: SelectCommand="select * from...
7
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work...
1
by: Randy | last post by:
In VS 2005, in the Windows Controls, you have the DataGridView (which has scrollbars). In the WebControls, is the GridView or the DataList synonymous with the DataGridView? Can you have...
0
OuTCasT
by: OuTCasT | last post by:
Hi all. here is my dilemma. i have 4 dropdownlisboxes on my web page. you select each value from the listboxes and the results are displayed on a gridview on the same page. the gridview has a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.