Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Datagrid Display - right align numbers

  Asked By: Josefina    Date: Nov 24    Category: Asp.net    Views: 3018

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?



3 Answers Found

Answer #1    Answered By: Clayton Richardson     Answered On: Nov 24

Have you tried HorizontalAlign="Right"?

Answer #2    Answered By: Adelinda Fischer     Answered On: Nov 24

First, you are not required to use the onItemDataBound event  to format
numbers instead use the DataFormatString


<asp:BoundColumn DataField=myData
DataFormatString="#,##0.00" ItemStyle-HorizontalAlign="right" />


Answer #3    Answered By: Tamara Nguyen     Answered On: Nov 24

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 type
using the  format  string to add   , and decimal formatting
Now with your tip on alignment   - setting the  cell   .horizontalalign = horizontalalign.right

The dataformatstring won’t work on a string money field in the datasource table.

Didn't find what you were looking for? Find more on Datagrid Display - right align numbers Or get search suggestion and latest updates.