Change item-template value format...

J

Julius Fenata

Dear all,

I need help to change my item-template value format...

Here is my case, I have a datagrid, with 'SubjectPrice' field, and when the
grid displayed, my 'SubjectPrice' field displayed as this format:
$30,000.00, because I put it this format {0:C}.

I need to re-format as only this value (example: 30.000 - without currency,
without decimal & using dot for thousand separator). But how to re-format my
field, considering that formatting in datagrid is limited on formatting?

I have one code to reformat into desire format (XX.XXX format), but I have
put it in my code-behind, how to applied this format into my datagrid?

Here is my code:

private NumberFormatInfo NumberFormat_Convert()
{
NumberFormatInfo myNumberFormat = new CultureInfo("id-ID").NumberFormat;
myNumberFormat.NumberGroupSeparator = ".";
myNumberFormat.NumberDecimalDigits = 0;
return myNumberFormat;
}

SubjectPrice = (Convert.ToDecimal(SubjectPrice)).ToString("N",
NumberFormat_Convert());

How to applied that format into my 'SubjectPrice' field on the datagrid?

I have thinking to change my 'SubjectPrice' into an item-template format, so
could easily put any code on it, but I haven't has any experience on this...

This is my item-template:

<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.SubjectPrice", "{0:C}") %>'> // Return: $30,000.00
</asp:Label>
</ItemTemplate>

Please, kindly elaborate this case, until I got this format (Expected:
30.000 --> XX.XXX format - without currency, without decimal & using dot for
thousand separator).

Thx In Advance,
Julius Fenata
 
M

MattC

try something like:

<ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# Format(
DataBinder.Eval(Container,"DataItem.SubjectPrice") ) %'>
</asp:Label>
</ItemTemplate>

And in code behind place:

protected string Format(object myValue)
{
return (Convert.ToDecimal(myValue)).ToString("N",NumberFormat_Convert());
}

MattC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top