In the old UltraWebGrid you made a column format to currency by doing something like this.
grdResults.Columns[0].Format = "$###,###,##0.00";
How do you achieve this same effect with the new WebDataGrid?
Thanks!
Hi whanes,
In the WebDataGrid, BoundDataField and UnboundField both have a DataFormatString that can be used to format how data is displayed. For example:this.WDG1.Columns[0].DataFormatString= "{0:c}";
Be warned that if you autogenerate columns, those are not available in the Columns collection.
regards,
David Young
I guess I am auto generating columns then, as this is the error I am getting when i try that.
Error 7 'Infragistics.Web.UI.GridControls.GridField' does not contain a definition for 'DataFormatString' and no extension method 'DataFormatString' accepting a first argument of type 'Infragistics.Web.UI.GridControls.GridField' could be found (are you missing a using directive or an assembly reference?) 54 66
Please feel free to contact us if you have any further questions regarding this matter.
Well, if you have not created any columns in your code behind or defined them in the aspx, the Columns collection will be empty. You'll need to define columns to access them in this way. Another option would be to access the column (our internally stored one) off a cell of that column. For example. grid.Rows[0].Items[0].Column.
-Dave
Ok I am still having some issues here. Ill admit i am not the most experinced Web Dev and I am probably missing something simple but here is what is going on.
I do
grdResults.DataSource = GetData();
grdResults.DataBind();
Then to format the column.
((Infragistics.Web.UI.GridControls.BoundDataField)grdResults.Columns[grdResults.Columns.Count - 1]).DataFormatString = "{0: $###,###,##0.00}";
I think get a object not set to a instance error, which appears to be because the columns in the grid do not exist yet. Which is rather confusing.
What exactly do i need to do to correct this? Thanks so much!
HI,
If you were only autogenerating columns, you would have gotten a null ref exception or index out of bounds. The problem is you did not type cast. The indexer for Columns returns a GridField. DataFormatString does not exist on this class. You need to typecast to BoundDataField, UnboundField (if it actually is one) or the super class of both, FormattedGridField.