Link to home
Start Free TrialLog in
Avatar of ROBERT MECHLER
ROBERT MECHLERFlag for United States of America

asked on

Left aligned $ and right aligned amount ASP.NET

The following code places a $ one space to the left of the dollar amount in a grid cell. The value placed in the Text field is processed using the following code:
 <asp:Label runat="server" ID="MaketvalueLabel" Text='<%# String.Format("{0}{1}","$ ",String.Format("{0:n}",Eval("MarketValue"))) %>'
   ForeColor='<%# Convert.ToInt32(Eval("MarketValue")) >=0
System.Drawing.Color.Black:System.Drawing.Color.Red%>'>
                    ></asp:Label>


Text='<%# String.Format("{0}{1}","$ ",String.Format("{0:n}",Eval("MarketValue"))) %>'

Open in new window


The code that needs a String.Format is    "$ "
Either left aligned in the cell or padded with spaces to the right of the $ . I tried adding spaces and no changes. I tried using String.Fromat( "{0,-15} ... but no change.


So far none of the samples I've found give me a $ that is left aligned so that they appear on the web page in a grid vertically and left aligned.
Avatar of HainKurt
HainKurt
Flag of Canada image

Text='<%# "$ " + Eval("MarketValue") %>'

or

Text='<%# "$ " & Eval("MarketValue") %>'

what do you get?
Avatar of ROBERT MECHLER

ASKER

I get something like      $ 390,300.33
                                                  $ 30.23
                                            $ 23.499.43

I've actually decided to just insert a column into the grid with a value of '$'. Much simpler.
add this to label

style="text-align: left;"
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Both provide a part of the solution. Thanks
The Grid Cell was too large and left aligning or creating another column did not look right.  The float left looked much closer to what I needed