Hi Devron,
Based on my understanding, your objective here is to set DataFormatString
of auto-generated columns (DataGrid.AutoGenerateColumns = true) of
DataGrid. Please feel free to let me know if I've misunderstood anything.
Currently it's not easy to achieve this objective using simple property
setting, since the auto-generated columns are not added to DataGrid.Columns
collection and they're not accessible from outside. We have to inherit from
DataGrid and override CreateColumnSet to get references to the
auto-generated columns:
namespace myns
{
public class MyDataGrid : DataGrid
{
protected override System.Collections.ArrayList
CreateColumnSet(PagedDataSource dataSource, bool useDataSource)
{
ArrayList al = base.CreateColumnSet(dataSource, useDataSource);
foreach (DataGridColumn col in al)
{
BoundColumn bc = col as BoundColumn;
if (bc != null)
{
bc.DataFormatString = "{0:dd/MM/yyyy}";
}
}
return al;
}
}
In your ASPX:
<%@ Register TagPrefix="c" Namespace="myns" Assembly="__code" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<c:MyDataGrid ID="grid1" runat="server"></c:MyDataGrid>
(Assembly="__code" assumes you're using MyDataGrid from a class file in
App_Code)
Also note this is a quick and dirty hack without checking for the column's
actual data type, you may want to use Reflector
(http://www.aisto.com/roeder/dotnet/) to insepect implementation of
DataGrid.CreateAutoGeneratedColumns to see how to get each column's binding
data's type.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Devron Blatchford - 09 Oct 2007 00:06 GMT
Thanks Walter But.....
This seems overly complicated. It was working on the server that I moved it
from which leads me to beleive there must be a setting that the date format
defaults from somewhere?
I failed to mention previously that both the servers I moved from/to are
Server2003 and running .NET 1.1 app.
All settings on the servers I can see have the date format in d/mm/yy set.
I am not keen to change the source code if it is not required so I was
hoping to find the formatting setting somewhere or somehow force ASP.NET to
use what I specify by default.
Thanks Again.
Devron Blatchford
Devron Blatchford - 09 Oct 2007 04:21 GMT
Ok, I fixed this by setting the culture string in the header of the aspx file:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="RunExtract.aspx.vb" Inherits="DEX.RunExtract" Culture="en-AU"%>
Thanks

Signature
Devron Blatchford
> Hi Devron,
>
[quoted text clipped - 63 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 09 Oct 2007 07:19 GMT
Hi Devron,
Thanks for your update.
I was just about to post the information about setting Culture specifically
in your page or web.config. Though please note that setting Culture will
determine the results of culture-dependent functions (such as date, number,
and currency formatting, etc.). Depending on your actual requirement, this
may or may not have impact on your other functionality of your web
application.
#How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
http://msdn2.microsoft.com/en-us/library/bz9tc508.aspx
Please feel free to let me know if you have anything unclear.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.