T
Tim Mackey
hi,
with a derived DataGrid control, i can override the CreateColumnSet method
and scan into the DataGridColumns and set the DataFormatString, e.g. leave
out the time part of a DateTime value. this works great for a DataGrid
control.
however i'm upgrading this control to inherit from GridView. there seems to
be a limitation of the gridview "Method not supported" when you try and set
a DataFormatString on an AutoGeneratedField.
here's the code:
[ToolboxData("<{0}:SmartGridView runat=server></{0}:SmartGridView>")]
public class SmartGridView : GridView
{
public SmartGridView()
{
}
protected override ICollection CreateColumns(PagedDataSource dataSource,
bool useDataSource)
{
ArrayList arr = (ArrayList)base.CreateColumns(dataSource, useDataSource);
foreach (AutoGeneratedField f in arr)
f.DataFormatString = "{0:dd/MM/yyyy}"; // throws exception
return arr;
}
}
here's the exception:
[NotSupportedException: Specified method is not supported.]
System.Web.UI.WebControls.AutoGeneratedField.set_DataFormatString(String
value) +1839359
SmartGridView.CreateColumns(PagedDataSource dataSource, Boolean
useDataSource)
it makes no difference if i cast the AutoGeneratedField to a BoundField.
does anyone know how you can do this? seems strange that the GridView would
lose some features of the DataGrid.
thanks in advance
tim
with a derived DataGrid control, i can override the CreateColumnSet method
and scan into the DataGridColumns and set the DataFormatString, e.g. leave
out the time part of a DateTime value. this works great for a DataGrid
control.
however i'm upgrading this control to inherit from GridView. there seems to
be a limitation of the gridview "Method not supported" when you try and set
a DataFormatString on an AutoGeneratedField.
here's the code:
[ToolboxData("<{0}:SmartGridView runat=server></{0}:SmartGridView>")]
public class SmartGridView : GridView
{
public SmartGridView()
{
}
protected override ICollection CreateColumns(PagedDataSource dataSource,
bool useDataSource)
{
ArrayList arr = (ArrayList)base.CreateColumns(dataSource, useDataSource);
foreach (AutoGeneratedField f in arr)
f.DataFormatString = "{0:dd/MM/yyyy}"; // throws exception
return arr;
}
}
here's the exception:
[NotSupportedException: Specified method is not supported.]
System.Web.UI.WebControls.AutoGeneratedField.set_DataFormatString(String
value) +1839359
SmartGridView.CreateColumns(PagedDataSource dataSource, Boolean
useDataSource)
it makes no difference if i cast the AutoGeneratedField to a BoundField.
does anyone know how you can do this? seems strange that the GridView would
lose some features of the DataGrid.
thanks in advance
tim