I'm currently working with a utility that was written using the Infragistics WebDataGrid control. The tool allows a user to select a table from a drop-down list at which point it runs a stored procedure to get data from SQL Server which it then binds to the grid.
Everything gets a default format, which for datetime columns is simply MM/DD/YYYY
in this case. There is a request to include the time component for at least one of these columns.
After much searching I've tried to add code to the _InitializeRow
event handler for the grid, but I can't seem to get it quite right. Here's what I've come up with:
if (e.Row.Index == 0)
{
foreach (GridRecordItem field in e.Row.Items)
{
if (field.Column.Key == "InsertedOnCC")
field.Column.FormatValue = "{0:g}";
}
}
This gives me an error that FormatValue
cannot have a value assigned because it is a method group.
This was pieced together from several sources, none of which did quite what I wanted to do. For example, one piece of sample code just always assumed that the column in question was the first column, so I had to add the foreach
loop.
I've seen a lot of mention of BoundDataField
and DataFormatString
, but I can't seem to actually find how to access those.
NOTE: I'm actually a SQL Developer, not a C# developer, so please be gentle. :)
Thanks!
I was able to sort this out by casting the Column
as a BoundDataField
then using the DataFormatString
from there:
if (e.Row.Index == 0)
{
foreach (GridRecordItem gri in e.Row.Items)
{
BoundDataField field = gri.Column as BoundDataField;
if (field.Key == "InsertedOnCC")
field.DataFormatString = "{0:g}";
}
}