I am display a Datagrid using the auto matically generating the columns from a dataset.I’m using the onItemDataBound event to format numbers with #,##0.00 .Now I want to right align the text in the cell.How to I add a Column or even Cell level attribute for alignment .Can I do this in the RENDER method ?If so, can I have an example?
Have you tried HorizontalAlign="Right"?
First, you are not required to use the onItemDataBound event to formatnumbers instead use the DataFormatString
<columns><asp:BoundColumn DataField=myDataDataFormatString="#,##0.00" ItemStyle-HorizontalAlign="right" /></columns>
Since, my datasource table is a Reporting Summary Table and the columns are all string and not money data types etc, I am using the onItemDatabound event to:convert the money fields to a decimal typeusing the format string to add , and decimal formattingNow with your tip on alignment - setting the cell .horizontalalign = horizontalalign.rightThe dataformatstring won’t work on a string money field in the datasource table.