This is a migrated thread and some comments may be shown as answers.

parentheses for negatives

1 Answer 266 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gino Suarez
Top achievements
Rank 1
Gino Suarez asked on 26 Jan 2010, 10:14 PM
Hi ,
How could i set parentheses for negatives using boundcolumns without currency symbol something like this

(1,980.70)

actually i have this dataformatstring , and its cool 'cause completes the decimal position with #.00 always
<telerik:GridBoundColumn    DataField="Noviembre" Aggregate="Sum" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:N2}" DataType="System.Decimal" 
                                                                            FooterAggregateFormatString="{0:N2}" FooterStyle-Font-Bold="true"
                                                                             <HeaderStyle HorizontalAlign="Right" /> 
                                                                             <ItemStyle HorizontalAlign="Right" /> 
                                                                     <FooterStyle HorizontalAlign="Right" /> 
                                                </telerik:GridBoundColumn> 
wih this code and setting the dataformatstring={"0:C"} parentheses works but whit the currency symbol
CultureInfo ci = new CultureInfo("es-PE"); 
ci.NumberFormat.CurrencyNegativePattern = 14
System.Threading.Thread.CurrentThread.CurrentCulture = ci

i hope you can help me, thanks

Regards
Gino


1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jan 2010, 10:38 AM
Hi Gino,

You can try the following approach in order to add parentheses if the value is negative.

CS:
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            if (dataItem["Number"].Text != "&nbsp;"
            { 
                if (Convert.ToDouble(dataItem["Number"].Text) < 0) 
                { 
                    string dbl = dataItem["Number"].Text.ToString(); 
                    string str = String.Format("({0})", dbl); 
                    dataItem["Number"].Text = str; 
                } 
            } 
        } 
    } 

-Shinu.
Tags
Grid
Asked by
Gino Suarez
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or