By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,717 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,717 IT Pros & Developers. It's quick & easy.

Change item-template value format...

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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",NumberFo rmat_Convert());
}

MattC

"Julius Fenata" <id****@gmx.net> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.